在上篇文章《渗透基础——端口转发与代理》提到了使用go语言分别实现正向和反向socks代理的方法,不仅开发效率高,而且能够很方便的实现跨平台编译。 本文将要进一步介绍Windows系统和Kali系统下使用Go语言开发的完整过程,并基于开源代码,实现一个socks正向和反向代理的工具,记录细节。
本文将要介绍以下内容:
· Windows系统下Go语言开发环境的搭建
· Kali系统下Go语言开发环境的搭建
· 工具代码细节
· 开源完整实现代码
测试系统: Win7x64
1、安装Go
下载安装:
https://golang.org/dl
或者
https://studygolang.com/dl
2、安装git
https://gitforwindows.org/
用来下载第三方开发包
1、安装第三方包
需要以下三个:
· golang.org/x/net/context
· https://github.com/armon/go-socks5
· https://github.com/hashicorp/yamux
安装流程如下:
(1)安装golang.org/x/net/context
go-socks5依赖,否则安装时会提示:
在线安装:
通常会失败,这里可以先从github下载再离线安装。
完整命令如下:
注意这里使用的路径为GOROOT,默认路径为C:Go,可通过输入go env查看。
(2)安装go-socks5
在线安装:
如果安装失败,同样先从github下载再离线安装。
完整命令如下:
cd %USERPROFILE%gosrc
git clone https://github.com/armon/go-socks5.git
go install go-socks5
需要注意这里使用的路径为%USERPROFILE%go,即GOPATH,而不是GOROOT,可通过输入go env查看。
如果使用GOROOT,会出现如下错误:
(3)安装yamux
在线安装:
离线安装:
git clone https://github.com/hashicorp/yamux
go install yamux
2、实现代码
我这里参考了https://github.com/brimstone/rsocks
添加了正向代理的功能,并在结构上做了调整,区分正向和反向代理。
完整实现代码:
https://github.com/3gstudent/Homework-of-Go/blob/master/frsocks.go
3、跨平台编译
正常编译命令如下:
编译成功后生成文件frsocks.exe
想要指定输出文件名,这里需要先将frsocks.go重命名为main.go,再分别使用以下代码进行跨平台编译
(1)Windows 32位
SET GOOS=windows
SET GOARCH=386
go build -o frsocks_windows_386
(2)Windows 64位
SET GOOS=windows
SET GOARCH=amd64
go build -o frsocks_windows_adm64
(3)linux arm64
SET GOOS=linux
SET GOARCH=amd64
go build -o frsocks_linux_amd64
所有支持的系统如下:
· androidarm
· darwin386
· darwinamd64
· darwinarm
· darwinarm64
· dragonflyamd64
· freebsd386
· freebsdamd64
· freebsdarm
· linux386
· linuxamd64
· linuxarm
· linuxarm64
· linuxppc64
· linuxppc64le
· linuxmips
· linuxmipsle
· linuxmips64
· linuxmips64le
· linuxs390x
· netbsd386
· netbsdamd64
· netbsdarm
· openbsd386
· openbsdamd64
· openbsdarm
· plan9386
· plan9amd64
· solarisamd64
· windows386
· windowsamd64
来自https://golang.org/doc/install/source#environment
0x04 Kali系统下Go语言开发环境的搭建
测试系统: Kali2
1、安装Go
下载:
或者
安装:
测试:
echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile
source /etc/profile
go
1、安装第三方包
需要以下三个:
· golang.org/x/net/context
· https://github.com/armon/go-socks5
· https://github.com/hashicorp/yamux
(1)安装golang.org/x/net/context
mkdir /usr/local/go/src/golang.org/x
cd /usr/local/go/src/golang.org/x
git clone https://github.com/golang/net.git
go install golang.org/x/net/context
(2)安装go-socks5
mkdir /root/go/src
cd /root/go/src
git clone https://github.com/armon/go-socks5.git
go install go-socks5
(3)安装yamux
git clone https://github.com/hashicorp/yamux
go install yamux
2、实现代码
https://github.com/3gstudent/Homework-of-Go/blob/master/frsocks.go
3、跨平台编译
正常编译命令如下:
编译成功后生成文件frsocks。
想要指定输出文件名,这里需要先将frsocks.go重命名为main.go,再分别使用以下代码进行跨平台编译。
(1)Windows 32位
(2)Windows 64位
(3)linux arm64
其它环境见https://golang.org/doc/install/source#environment
实现全平台编译的批处理文件已上传至github,地址如下:
https://github.com/3gstudent/Homework-of-Go/blob/master/windows_build.bat
1、正向代理
如下图:
Client:
使用代理工具连接Client的1080端口
2、反向代理
如下图:
Client:
Transit server:
使用代理工具连接Client的2222端口。
本文介绍了Windows系统和Kali系统下使用Go语言开发的完整过程,基于开源代码,实现了一个socks正向和反向代理的工具。
本文来源于:渗透基础——使用Go语言开发socks代理工具-变化吧博客
特别声明:以上文章内容仅代表作者本人观点,不代表变化吧博客观点或立场。如有关于作品内容、版权或其它问题请于作品发表后的30日内与变化吧联系。
- 赞助本站
- 微信扫一扫
-
- 加入Q群
- QQ扫一扫
-
评论