利用frp远程控制Windows
电脑必须已经开始Windows远程控制服务,并且在同一局域网内可以访问到.
要求:
- 一台公网的服务器.
- 一台开启远程控制服务的Windows电脑,一般默认端口是 3389
- IP: 47.52.253.211
frp 的Github地址. https://github.com/fatedier/frp
下载地址: https://github.com/fatedier/frp/releases
Linux服务器配置
mkdir config
cd config
vim remote.ini
写入:
[common]
bind_port = 7004
服务器记得开启防火墙
启动
./frps -c config/remote.ini
# Windows
frps.exe -c config/remote.ini
启动脚本:
#!/bin/sh
# PS some OS location: /usr/sbin/cronolog OR /usr/local/sbin/cronolog
CRONOLOG_PATH=/usr/local/sbin/cronolog
if [ ! -f "$CRONOLOG_PATH" ]; then
CRONOLOG_PATH=/usr/sbin/cronolog
fi;
SERVER=$(cd `dirname $0`; pwd)
cd $SERVER
# 这里写入ini 文件所在路径,frps 跟当前脚本必须在同一个文件夹
INI_PATH="$SERVER/config/remote.ini"
SHELL_NAME=$(basename $0)
#LOG_PATH="$SHELL_NAME"_logs
#echo $LOG_PATH
HELP_INFO="usage: { start | start configFilePath | stop | fstop | restart }"
if [ $# -eq 0 ];then
echo $HELP_INFO
else
case "$1" in
start)
if [ $# -gt 1 ]; then
INI_PATH="$SERVER/$2"
fi;
echo "using config ini file path = [$INI_PATH]"
RUN="$SERVER/frps -c $INI_PATH" # 2>&1 | $CRONOLOG_PATH $SERVER/logs/$SHELL_NAME/nohup_%Y%m%d.log" &
nohup $RUN 2>&1 | $CRONOLOG_PATH ./logs/$SHELL_NAME/nohup_%Y%m%d.log &
echo $[$!-1] > $SERVER/$SHELL_NAME.pid
;;
stop)
kill `cat $SERVER/$SHELL_NAME.pid`
rm -rf $SERVER/$SHELL_NAME_server.pid
;;
fstop)
kill -9 `cat $SERVER/$SHELL_NAME.pid`
rm -rf $SERVER/$SHELL_NAME_server.pid
;;
restart)
$P stop
sleep 1
$P start
;;
np)
DATE=$(date +%Y%m%d)
NO_PATH=$SERVER/logs/$SHELL_NAME/nohup_
tail -f "$NO_PATH$DATE.log" | perl -pe 's/('$2')/\e[1;31m$1\e[0m/g'
;;
*)
echo $HELP_INFO
;;
esac
fi;
exit 0
脚本用法:
./shell start # 启动
./shell stop # 关闭
./shell fstop # 强制关闭 kill -9
./shell np # 查看今天日志
连接客户端配置
配置文件: remote_client.ini
[common]
server_addr = 47.52.253.211
server_port = 7004
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 7005
启动:
frpc.exe -c remote_client.ini
访问端
打开Windows
自带的远程控制,**Win + R **,输入mstsc
输入:47.52.253.211:7005`
二.安全版
上面的方法,直接把电脑暴露在公网上,虽然电脑有密码,但还是感觉不太安全的样子.
服务器配置同上
被控制的电脑
写入,配置文件remote_client_se.ini
:
[common]
server_addr = 47.52.253.211
server_port = 7004
[secret_ssh]
type = stcp
local_ip = 127.0.0.1
sk = [email protected]
local_port = 3389
remote_port = 7005
sk:就是访问的密码.
启动:
frpc.exe -c remote_client_se.ini
远程访问电脑的配置(在用PC)
这一步,启用密码访问才需要,当我们需要控制远程电脑的时候,本机也要配置
配置文件:remote_visitor.ini
[common]
server_addr = 47.52.253.211
server_port = 7004
[secret_ssh_visitor]
type = stcp
role = visitor
server_name = secret_ssh
sk = [email protected]
bind_addr = 127.0.0.1
bind_port = 7005
sk要一样
frpc.exe -c remote_visitor.ini
远程连接地址为: 127.0.0.1:7005
被控制PC开机启动
Windows+R运行,输入gpedit.msc
进入组策略编辑器
脚本名:
C:\Users\VM\Desktop\remote-desktop-controll\frpc.exe
脚本参数:
-c C:\Users\VM\Desktop\remote-desktop-controll\remote_client_se.ini
确定就OK.