前言

作为搞机发烧友之一 && 实习时长3月半的渗透实习生,最近自己倒腾了一下备用手机,在里面放置了SSH程序并通过Magisk挂载运行,同时又放置了一个Kali系统用于chroot挂载使用,在自己需要时能够随时操作,便自写了一些脚本方便该系统的挂载与卸载,这样无时无刻手机将成为个人的移动渗透工具。
image-20220327154426357

在不满足自己只能在本地以及局域网环境使用情况下,遂想到将SSH服务穿透出去通过终端命令控制对其进行操作。这样在公司即可直接SSH控制放置在学校的手机进行相关渗透操作(日常简单渗透或测试时懒得开虚拟机 -_-!)。传统的通过软件控制的FRPC可能会遭到MIUI系统的无情Kill(即使已设置自启动并设置电源管理选项)以及需要设备开机时便能够运行,还能够自检配置文件进行重载,于是自写了一个通过Magisk挂载守护运行的FRPC模块。

如何食用

该模块已上传至Github并开源,项目链接:

模块支持arm64armamd64x86架构的设备。
在Magisk中安装模块后,前往Android/frpc目录下配置frpc.ini文件,然后重启设备即可在您终端设备上守护运行FRPC程序。
FRPC-Run-status.png

源码构建ZIP

正常情况直接下载release处的zip包在Magisk中安装,若您的Magisk版本高于24.0,后续更新直接在Magisk中即可。

为保证模块不被破坏,模块安装时校验模块内部相关文件sha256信息,传统的直接打ZIP包方式已不可行。下面自己写了个脚本用于对项目源码ZIP包构建,给其它二次构建着方便自主构建食用。

对模块若有更多想法或补充的欢迎Github提issue或文下留言补充。


将如下代码保存至脚本文件中,脚本文件放置于与模块文件夹的同目录下,勿放置在模块文件夹目录下。
然后根据帮助信息构建zip包即可。

脚本代码如下:

#!/usr/bin/bash
######################## Script Info #########################
# 
# author:Yang2635
# blog:https://www.isisy.com
# github: https://github.com/Yang2635
# module name: Magisk-FRPC
#
############## 脚本仅限 Magisk-FRPC 模块测试使用!##############
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" &&  Font_color_suffix="\033[0m"
SHELL_DIR=$(dirname $(readlink -f "$0"))

# Check sha256sum\zip\unzip binary
# Use the user's default PATH environment
sha256sum_bin=$(which sha256sum 2>/dev/null)
zip_bin=$(which zip 2>/dev/null)
unzip_bin=$(which unzip 2>/dev/null)
[[ -z "$sha256sum_bin" ]] && echo -e "${Red_font_prefix}The sha256sum binary file was not found !${Font_color_suffix}\n" >&2 && exit 1
[[ -z "$zip_bin" ]] && echo -e "${Red_font_prefix}The zip binary file was not found !${Font_color_suffix}\n" >&2 && exit 1
[[ -z "$unzip_bin" ]] && echo -e "${Red_font_prefix}The unzip binary file was not found !${Font_color_suffix}\n" >&2

# Check file sha256sum
Check_File_sha256(){
    dir_path=$(realpath $1)
    echo -e "\nThe file sha256 information is as follows:\n"
    [[ ! $(ls -A $dir_path 2>/dev/null) ]] && echo -e "${Red_font_prefix}Folder ${dir_path} is empty !${Font_color_suffix}\n" >&2 && exit 1
    find $(realpath $dir_path) -type f -exec $sha256sum_bin {} \;
}

# Clear sha256sum file
Clear_sha256sum_file(){
    echo -e "\nStart clearing sha256sum files:"
    find $1 -type f -name "*.sha256sum" -exec rm {} \;
    if [[ $? -eq 0 ]]; then
        echo -e "${Green_font_prefix}The sha256sum file was cleaned successfully ! ${Font_color_suffix}\n"
    else
        echo -e "${Red_font_prefix}Failed to clean sha256sum file ! ${Font_color_suffix}\n" >&2
        exit 1
    fi
}

# Calculate sha256sum
Calc_file_sha256sum(){
    echo -e "\nStart calculating sha256:"
    [[ ! -d $1 ]] && echo -e "${Red_font_prefix}The parameter specified is not a directory !${Font_color_suffix}\n" >&2 && exit 1
    [[ ! $(ls -A $1 2>/dev/null) ]] && echo -e "${Red_font_prefix}Folder $1 is empty !${Font_color_suffix}\n" >&2 && exit 1
    if [[ -f "${SHELL_DIR}/$(basename $1).zip" ]];then
        echo -e "${Red_font_prefix}There are old compressed files, please delete the files first ! \nFile Path: ${SHELL_DIR}/$(basename ${1}).zip ${Font_color_suffix}\n" >&2
        exit 1
    fi
    find $1 -path $1/.git -prune -o -type f -exec $sha256sum_bin {} \; | sort > ./sha256sum_result.lst
    if [[ $? -eq 0 ]]; then
        echo -e "${Green_font_prefix}sha256 calculation succeeded !${Font_color_suffix}\n"
    else
        echo -e "${Red_font_prefix}sha256 calculation failed !${Font_color_suffix}\n" >&2
        [[ -f ./sha256sum_result.lst ]] && rm -f ./sha256sum_result.lst
        exit 1
    fi
}

# Start compressed file
Start_Comp(){
    echo -e "\nStart compressing files:"
    if [[ ! -d $1 ]];then
        echo -e "${Red_font_prefix}The parameter specified is not a directory !${Font_color_suffix}\n" >&2
        Clear_sha256sum_file ${1%/*}
        exit 1
    fi
    cd $1
    # Hidden files or directories are not compressed. e.g. .git
    $zip_bin -rq $(basename $1).zip ./* 2>/dev/null
    if [[ $? -eq 0 ]]; then
        echo -e "${Green_font_prefix}The zip file is generated successfully ! ${Font_color_suffix}"
    else
        echo -e "${Red_font_prefix}The zip file is generated failed ! ${Font_color_suffix}" >&2
        [[ -f "$(basename $1).zip" ]] && rm -f "$(basename $1).zip"
        Clear_sha256sum_file $1
        exit 1
    fi
    mv -f $(basename $1).zip ${SHELL_DIR}
    if [[ $? -eq 0 ]];then
        echo -e "${Green_font_prefix}The compressed file path is ${SHELL_DIR}/$(basename ${1}).zip${Font_color_suffix}"
    fi
}

# Generate file
Generate_file(){
dir_path=$(realpath $1)
Calc_file_sha256sum $dir_path
echo -e "\nStart writing sha256sum file:"
while read line
do
    sha256_sum=$(echo "$line" | awk '{print $1}')
    file_name=$(echo "$line" | awk '{print $2}')
    echo "$sha256_sum" > ${file_name}.sha256sum
    if [[ $? -eq 0 ]]; then
        echo -e "${Green_font_prefix}sha256:$sha256_sum write file: ${file_name}.sha256sum success !${Font_color_suffix}"
    else
        echo -e "${Red_font_prefix}sha256:$sha256_sum write file: ${file_name}.sha256sum failed !${Font_color_suffix}" >&2
        Clear_sha256sum_file $dir_path
        exit 1
    fi
done < ./sha256sum_result.lst
rm -f ./sha256sum_result.lst

Start_Comp $dir_path
Clear_sha256sum_file $dir_path
}

Help_Info(){
        cat<<-EOF

Usage: $0  [-cCgGhH]  <file/dir>

      -[?|h|H]             Give this help list.
      
      -[c|C] <file/dir>    Calculate the sha256 value of the file and print it to the terminal.

      -[g|G] <dir>         Generate verification file and generate compressed file.

    EOF
}

if [ ! "$1" ];then
    echo -e "\n${Red_font_prefix}The specified parameter is empty! Please see the help below !${Font_color_suffix}" >&2
    Help_Info
    exit 1
fi

while getopts ":c:C:g:G:hH" opt
do
    case $opt in
        c|C)
        Check_File_sha256 $OPTARG
        ;;
        g|G)
        Generate_file $OPTARG
        ;;
        h|H|?)
        Help_Info
        exit 1
        ;;
    esac
done

效果如下:

build_ZIP-file.png

End

本文标题:Magisk-FRPC 食用

本文链接:https://www.isisy.com/1276.html

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

声明:转载请注明文章来源。

最后修改:2022 年 07 月 03 日
如果觉得我的文章对你有用,请随意赞赏