-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipc.py
77 lines (71 loc) · 1.77 KB
/
ipc.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
#coding:utf-8
# from subprocess import Popen, PIPE, call
import sys,re,os,socket
reload(sys)
sys.setdefaultencoding('utf-8')
def host(filename):
'''从文件中获取局域网主机名'''
hostlist = []
host = open(sys.argv[1])
f = host.readlines()
regex = re.compile(r'\\')
for line in f:
if regex.findall(line):
hostlist.append(line.strip())
host.close()
return hostlist
def connect(hostlist):
'''ipc连接并列出C盘'''
num = 0
Truehost = {}
for i in hostlist:
hostname = i[2:]
'''获取主机名全部ip'''
try:
host1, host2, ip = socket.gethostbyname_ex(hostname)
ip = " ".join(ip)
except:
ip = " "
num = num + 1
print "####################[ %s ]#######################" %num
print " "
print "HOST: [%s]" %i
print "IP: [%s]" %ip
print " "
con = "net use %s\ipc$ %s /user:%s" %(i,sys.argv[3],sys.argv[2])
print con
Dir = "dir %s\c$" %i
Del = "net use %s /del /y" %i
print "Connection %s ..." %i
try:
con = os.popen(con)
if con.readlines():
print "[+] Ipc Connection Success !!!"
print "Dir Drive [c]"
Dirlist = os.popen(Dir)
if Dirlist.readlines():
print "[+] Drive C ACCESS !!!"
print "Del %s connect ..." %i
Truehost[i] = ip
os.popen(Del)
else:
print "[-] Drive C Deny"
else:
print "Ipc Connection failure"
except:
print "Error"
print " "
'''打印 成功连接主机'''
print "Host %s" %len(hostlist)
print "All Connection Host [%s]" %len(Truehost)
print " "
for Alivehost in Truehost:
print str(Alivehost) +" "+ Truehost[Alivehost]
if __name__ == '__main__':
if len(sys.argv) == 4:
hostlist = host(sys.argv[1])
print "Host [%s]" %len(hostlist)
connect(hostlist)
else:
print "use: net_ipc.py [host.txt] username password"