Skip to content

Instantly share code, notes, and snippets.

View RobinDavid's full-sized avatar

Robin David RobinDavid

View GitHub Profile
@RobinDavid
RobinDavid / dll_injection.py
Created February 25, 2014 17:49
Sample ddl injection (Gray Hat Python)
import sys
from ctypes import *
PAGE_READWRITE = 0x04
PROCESS_ALL_ACCESS = ( 0x000F0000 | 0x00100000 | 0xFFF )
VIRTUAL_MEM = ( 0x1000 | 0x2000 )
kernel32 = windll.kernel32 #Get the wanted dll
pid = sys.argv[1] #Gather sent parameters
@RobinDavid
RobinDavid / code_injector.py
Created February 25, 2014 17:45
sample of shellcode injection into a process (Gray Hat Python)
'''
Example taken from Gray Hat Python
The script inject a shellcode which tasks is to kill the given process, so that the process will not be killed by our process directly.
'''
import sys
from ctypes import *
# We set the EXECUTE access mask so that our shellcode will execute in the memory block we have allocated
PAGE_EXECUTE_READWRITE = 0x00000040
@RobinDavid
RobinDavid / pydbg_firefox.py
Created February 25, 2014 17:39
Pydbg: sample to hook a firefox function to retrieve credentials (Gray Hat Python book)
'''
Example taken from Gray Hat Python (book)
This script present a way to hook a DLL library in Firefox. For this example the script hook nspr4.dll which encrypt datas for SSL connection.
So we will be able to get the text before it is encrypted. Moreover we catch a pattern "password" to get all login/password before they are ciphered.
'''
from pydbg import *
from pydbg.defines import *
import utils
@RobinDavid
RobinDavid / pydbg_access_violation.py
Last active April 25, 2017 10:03
Pydbg: sample hook exception (access violation)
'''
#This commented program is vulnerable to a buffer overflow (copy it in a separate file)
from ctypes import *
msvcrt = cdll.msvcrt
raw_input("Once the debbuger is attached press any key") # Give the debugger time to attach, then hit a button
buffer = c_char_p("AAAAA") # Create the 5-byte destination buffer
@RobinDavid
RobinDavid / pydbg_hook_printf.py
Created February 25, 2014 17:29
Pydbg: sample hook printf function of a process
from pydbg import *
from defines import *
import struct
import random
def printf_randomizer(dbg):
# Read in the value of the counter at ESP + 0x8 as a DWORD
parameter_addr = dbg.context.Esp + 0x8
counter = dbg.read_process_memory(parameter_addr,4) #will be trigger when counter=4
@RobinDavid
RobinDavid / server_adv.py
Created February 25, 2014 17:24
Another sample of python server
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
import SocketServer
class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
self.request.send('hi ' + str(self.client_address) + '\n')
@RobinDavid
RobinDavid / pyunit_struct.py
Created February 25, 2014 17:19
Sample of a Pyunit test
import unittest
class Test1 (unittest.TestCase): #Define a class which extend unittest
def runTest(self):
self.failIf (1+1 != 2, '1+1 failed !')
def suite():
suite = unittest.TestSuite() #create an object testsuite
suite.addTest(Test1())
return suite
@RobinDavid
RobinDavid / rc4.py
Created February 24, 2014 21:16
RC4 algorithm implementation
def RC4(data, key):
x = 0
s = range(256)
for i in range(256):
x = (x + s[i] + ord(key[i % len(key)])) % 256
s[i], s[x] = s[x], s[i]
x = y = 0
out = ""
for c in data:
x = (x + 1) % 256
@RobinDavid
RobinDavid / html_parser.py
Created February 24, 2014 20:48
html parser in python to extract h1 text
from html.parser import HTMLParser #Import the parser
class HeadingParser(HTMLParser): #create a subclass of HTMLParser which will overload handle..
inHeading = False
def handle_starttag(self, tag, attrs): #Triggered when an opening tag is encountered
if tag == "h1": #if the tag is <h1>
self.inHeading = True #Change a variable which says we are in an header
print("Found a Heading 1")
def handle_data(self, data): #Triggered when data found (the content of the tag)
if self.inHeading: #Useless, used just to filter content of h1's
@RobinDavid
RobinDavid / jython_test.py
Created February 24, 2014 20:45
Just a sample of Jython script to use swing
#!/usr/bin/env jython
#-*- encoding:utf-8 -*-
from java.lang import System
from javax.swing import JFrame, JButton, JLabel
from java.awt import BorderLayout
# Exit application
def exitApp(event):
System.exit(0)