Skip to content

Instantly share code, notes, and snippets.

@lintile
Last active June 17, 2020 18:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lintile/df14034243770084f9bc4065ef4f7f7a to your computer and use it in GitHub Desktop.
Save lintile/df14034243770084f9bc4065ef4f7f7a to your computer and use it in GitHub Desktop.
Template for interacting with a netcat server
# A basic template for solving netcat challenges
# Author: aaron@lintile.com
import socket
import string
class Netcat:
def __init__(self, ip, port):
self.data_buffer = ''
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect((ip, port))
def read(self, length = 1024):
if len(self.data_buffer) < length:
increment = self.socket.recv(length - len(self.data_buffer))
self.data_buffer += increment
rval = self.data_buffer[:length]
self.data_buffer = self.data_buffer[length:]
return rval
def read_until_found(self, search_string):
""" Read into the buffer until we encounter the search string """
while not search_string in self.data_buffer:
increment = self.socket.recv(1024)
self.data_buffer += increment
pos = self.data_buffer.find(search_string)
rval = self.data_buffer[:pos + len(search_string)]
self.data_buffer = self.data_buffer[pos + len(search_string):]
return rval
def write(self, data):
self.socket.send(data)
def close(self):
self.socket.close()
import re
import itertools
import hashlib
nc = Netcat('insert.domain.here', 11235)
data = nc.read_until_found('?')
#TODO: Solve the challenge
nc.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment