Skip to content

Instantly share code, notes, and snippets.

View emandret's full-sized avatar
🎯
Focusing

Edwy M emandret

🎯
Focusing
  • London, United Kingdom
View GitHub Profile
@emandret
emandret / systemd-stub
Created June 27, 2023 17:34
Stub script to emulate systemd in WSL
#!/bin/bash
# NOTE: replace the root user shell by placing this script at /usr/local/bin/systemd-stub
# login user
user=ed
if [[ -p /dev/stdin ]] || [[ "$BASH_ARGC" -gt 0 ]]; then
shell=/bin/bash
else
#include <stdio.h>
#pragma pack(1)
struct my_struct
{
unsigned char b0;
unsigned char b1;
unsigned char b2;
unsigned char b3;
unsigned char b4;
@emandret
emandret / oidc_webapp.tf
Created March 22, 2023 10:25
Terraform snippet to setup Azure AD auth for an Azure web app using a custom OIDC provider
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.45.0"
}
}
}
provider "azurerm" {
@emandret
emandret / termios.c
Created November 15, 2021 13:00
Compare the canonical vs. noncanonical input modes of the TTY line driver
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#define MAX_BUFSIZE 4096
int main(int argc, char *argv[])
{
struct termios old_termios;
struct termios new_termios;
@emandret
emandret / qemu.sh
Created September 20, 2020 18:18
A simple bash script to launch and daemonize QEMU instances
#!/bin/bash
# daemonize a process by closing its file descriptors and detaching the process
# from its controlling terminal and the current session group
launch_daemon () {
$1 < /dev/null > /dev/null 2>&1 0<&- 1>&- 2>&- &
disown
}
# function to get the array key associated with one value
@emandret
emandret / reverse_shell.c
Created November 3, 2018 21:02
A simple reverse shell client
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#define REMOTE_ADDR "127.0.0.1"
@emandret
emandret / reverse_client.c
Created November 3, 2018 19:59
A socket example where the client act as the server by waiting for data and printing it
#include <arpa/inet.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#define REMOTE_ADDR "127.0.0.1"
#define REMOTE_PORT 4444
@emandret
emandret / offsetof.c
Created October 21, 2018 14:39
The linux kernel `offsetof` macro explained and implemented in pure C
#include <stdio.h>
/*
* In the expression `&ptr[5]` which is equivalent to `&(*(ptr + 5))`, we take
* the address of the fifth element which means an offset in bytes equal to `5 *
* sizeof(*ptr)` from the `ptr` base address. The address is simply retrieved as
* `ptr + 5` by the compiler and no memory access (i.e. dereferencing) is
* usually involved here.
*
* For a structure, the variable name represents the whole memory area from the
@emandret
emandret / pwned.c
Created October 14, 2018 22:04
MIME type upload exploit
#include <curl/curl.h>
#include <stdio.h>
int main(void)
{
/* Initialize request with curl */
CURL *req = curl_easy_init();
if (!req) {
fprintf(stderr, "Error: curl initialization failed");