Skip to content

Instantly share code, notes, and snippets.

View RobinDavid's full-sized avatar

Robin David RobinDavid

View GitHub Profile
@RobinDavid
RobinDavid / chg_mprotect.c
Created February 18, 2017 23:22
Changing the right on the text section to make it writeable
#define _GNU_SOURCE
#include <unistd.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <link.h>
#include <errno.h>
/*
- info: pointer to a dl_phdr_info {
ElfW(Addr) dlpi_addr; // Base address of object
@RobinDavid
RobinDavid / self_checksumming.c
Created February 18, 2017 23:25
PoC to checksum a given portion of the code
#define _GNU_SOURCE
#include <unistd.h>
#include <dlfcn.h>
#include <sys/mman.h>
#include <link.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
void *begin;
@RobinDavid
RobinDavid / create_pdf.py
Created April 6, 2017 15:21
Create a pdf from a set of jpg images
from fpdf import FPDF
from path import Path
import sys
imagelist = [x for x in sorted(Path(sys.argv[1]).listdir()) if x.ext == ".jpg"]
pdf = FPDF()
for im in imagelist:
pdf.add_page(orientation="P", format=(410,550)) #Size of images is known
@RobinDavid
RobinDavid / bin_diff.sh
Last active April 26, 2017 21:46
Binary diffing two files
#!/bin/zsh
#require zsh and colordiff (credits: https://superuser.com/questions/125376/how-do-i-compare-binary-files-in-linux)
diff -y <(xxd $1) <(xxd $2) | colordiff
@RobinDavid
RobinDavid / screenshot_webpage.py
Last active May 26, 2017 09:50
Take a webpage screenshot
from selenium import webdriver
import sys
url_input = ("file://" if not sys.argv[1].startswith("http") else "") + sys.argv[1]
image_output = sys.argv[2]
driver = webdriver.Chrome() # or PhantomJS() not to open a windows (require phantomjs)
driver.get(url_input)
if driver.save_screenshot(image_output):
print("Save ok !")
@RobinDavid
RobinDavid / wiki_first_image.py
Created June 12, 2017 16:06
Download the first image of a wikipedia article
import sys
import lxml.html
from path import Path
import wikipedia
import requests
def dl_image(search_str):
page = wikipedia.page(search_str)
html = lxml.html.fromstring(page.html())
imgs = html.xpath("//img")
@RobinDavid
RobinDavid / connect_kernel_client.py
Created March 23, 2018 15:25
Connecting programmatically (in python) to an existing jupyter kernel (from its file)
file = "/run/user/1000/jupyter/kernel-7365.json"
from jupyter_client.blocking import BlockingKernelClient
client = BlockingKernelClient(connection_file=file)
client.load_connection_file()
client.start_channels()
@RobinDavid
RobinDavid / deadline_exec.py
Created March 29, 2018 14:52
Launch a function in a proces with a timeout on the execution time.
from multiprocessing import Process, Queue
def deadline(timeout, f, *args):
queue = Queue() #using to get the result
def subproc_function(queue, f, *args):
res = f(*args)
queue.put(res)
proc = Process(target=subproc_function, args=(queue, f) +args) #creation of a process calling longfunction with the specified arguments
proc.start() #lauching the processus on another thread
try:
res = queue.get(timeout=timeout) #getting the resultat under 1 second or stop
@RobinDavid
RobinDavid / sum_share_size.py
Created August 8, 2019 15:37
Sum the size of all the shared libraries for a given dynamic ELF
#!/usr/bin/env python3
import sys
from pathlib import Path
import lddwrap
from hurry.filesize import size
def get_shared_size(filepath):
deps = lddwrap.list_dependencies(Path(filepath))
tot_size = 0
for d in deps:
@RobinDavid
RobinDavid / ida_snapshot_iter.py
Created April 10, 2020 21:52
IDA Pro iteratively restore all snapshots
import ida_kernwin
import ida_loader
ss = ida_loader.snapshot_t()
ida_loader.build_snapshot_tree(ss)
ccs = list(ss.children)
def callback(param1, param2):