SlideShare a Scribd company logo
Linux (game) hacking with
LD_PRELOAD
Hackersuli
2020 March
Hackersuli - Linux game hacking with LD_PRELOAD
Awesome LD_PRELOAD examples
•
libkeepalive
−enable TCP keepalive socket options
• libleakmydata
−disable SSL certificate verification
• libfaketime
−modifies the system time for a single application
Tux vs Timeskew
TIMESKEW="2 1"
LD_PRELOAD=./libtimeskew.so supertuxkart
TIMESKEW="1 2"
LD_PRELOAD=./libtimeskew.so supertux2
Log SSL/TLS
• rm -f hooklog.bin
• LD_PRELOAD=`pwd`/hook.so.1 wget
https://google.com
• ./print-hooklog hooklog.bin | head
Random, Debian style
#include <stdlib.h>
#include <stdio.h>
int main() {
srand(1);
int x = rand();
srand(2);
int y = rand();
puts(x == y ? "ok" : "fail");
return !(x == y);
}
LD_PRELOAD explained
man ld
#define _GNU_SOURCE - This is needed to be able to use
RTLD_NEXT, see later
#include - no need to explain these
void (*orig_srand)(unsigned int seed); - we define the original
srand here so we can use it later
void srand(unsigned int seed) { - override original srand function
if(!orig_srand) { - don't depend on a constructor to resolve libc's
function, and do it on demand when it's first needed.
LD_PRELOAD explained
man dlsym
orig_srand = dlsym(RTLD_NEXT, "srand"); - RTLD_NEXT finds
the next occurrence of a function in the search order after the
current library
dlsym - obtain address of a symbol in a shared object or
executable
assert(orig_srand); - abort program if we don’t have the original
srand
orig_srand(0); - call original srand with a fixed seed of 0
Random, Debian style
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <assert.h>
void (*orig_srand)(unsigned int seed);
void srand(unsigned int seed) {
if(!orig_srand) {
orig_srand = dlsym(RTLD_NEXT, "srand");
assert(orig_srand);}
orig_srand(0);}
Compiling and linking
gcc -Wall -fPIC -shared -o myldpreload.so ldpreload.c -ldl
-Wall – show all warnings
-fPIC – all function calls will be made via the Procedure
Linkage Table – PLT. Otherwise symbol relocations are
internally are resolved at load time, not good.
-shared – create a shared library
-ldl - tells the linker to find and link libdl.so, this is needed
by dlsym
Hacking vulnerable webserver
curl -X POST --data-binary @payload.so
http://<IP>/cgi-bin/cgitest?LD_PRELOAD=/proc/self/fd/0 -i
https://www.elttam.com//blog/goahead/
Because CGI was so secure back in 1999
Especially when the executable uses the LD_PRELOAD variable
and accepts it from the GET request
Can I privesc with LD_PRELOAD on
setuid/setgid binaries?
No *
* except if Defaults env_keep += LD_PRELOAD
#in suoders
Ghidra time
Note to self
Close everything, Skype, Spotify, Ghidra, ...
Pwnadventure
sudo gdb -p $(pidof PwnAdventure3-Linux-
Shipping)
• p GameWorld
• p *GameWorld
• p *(ClientWorld *) GameWorld
Pwnadventure
Print class definition:
− ptype ClientWorld
− ptype Player
copy to libGameLogic.h
p *(Player*)((*(ClientWorld*)GameWorld).m_activePlayer.m_object)
set variable=value
Fixing things
std::string vs const char*
std::string is an object holding the string data
const char* is a pointer
health: public vs protected
-std=c++11
Hiding on top of the tree
Frida vs LD_PRELOAD
When to use Frida and when to LD_PRELOAD
Frida is better for quick one-time hacks
LD_PRELOAD is nice when you want to share the
love with everyone
LD_PRELOAD is better when it is used in
production, e.g. a code is fixed
Bonus macOS
DYLD_INSERT_LIBRARIES is the LD_PRELOAD
By default, when System Integrity Protection is
enabled and and the program has the
CS_RESTRICT flag (Apple shipped binaries),
DYLD_INSERT_LIBRARIES will not work
Sad Panda
Basic macOS syntax
#include <stdio.h>
#include <syslog.h>
__attribute__((constructor))
static void customConstructor(int argc, const char **argv)
{
printf("Hello from dylib!n");
syslog(LOG_ERR, "Dylib injection successful in %sn", argv[0]);
}
gcc -dynamiclib inject.c -o inject.dylib
DYLD_INSERT_LIBRARIES=inject.dylib ./test
Prevent LD_PRELOAD
• statically link your program
• setuid/setgid set
• check for the LD_PRELOAD environment
variable, and complain
○ the attacker could also LD_PRELOAD the
function that lets you read environment
variables… :)
Prevent
DYLD_INSERT_LIBRARIES
• setuid and/or setgid bits are set
• restricted by codes signed with entitlements
• restricted segment
https://theevilbit.github.io/posts/dyld_insert_libraries_dylib_injection_in_macos_osx_deep
_dive/
References
LiveOverFlow !!!!
https://github.com/LiveOverflow/PwnAdventure3/tree/master/tools/linux
https://github.com/gaul/awesome-ld-preload
https://theevilbit.github.io/posts/dyld_insert_librari
es_dylib_injection_in_macos_osx_deep_dive/
Thank you for your
attention

More Related Content

What's hot (19)

PDF
Syslog Protocols
Martin Schütte
 
PPT
GStreamer 101
yuvipanda
 
PDF
Ostinato FOSS.IN 2010
pstavirs
 
PPT
Raspberry Pi for IPRUG
Frank Carver
 
PPTX
Flex pod driven by Openstack
Marton Kiss
 
PDF
CS 626 - March : Capsicum: Practical Capabilities for UNIX
ruchith
 
PDF
Packet crafting of2013
Shteryana Shopova
 
PDF
Software Packaging for Cross OS Distribution
Jian-Hong Pan
 
PDF
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Codemotion
 
PDF
Pipework: Software-Defined Network for Containers and Docker
Jérôme Petazzoni
 
PPTX
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
oholiab
 
PDF
Shall we play a game?
IngridRivera36
 
PPTX
Shall we play a game?
Maciej Lasyk
 
PDF
tokyotalk
Hiroshi Ono
 
PDF
LCA14: LCA14-412: GPGPU on ARM SoC session
Linaro
 
PDF
Introduction GStreamer
Shih-Yuan Lee
 
PPTX
Introduction to Gstreamer
Rand Graham
 
PPTX
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Ravi Rajput
 
PDF
Spying on the Linux kernel for fun and profit
Andrea Righi
 
Syslog Protocols
Martin Schütte
 
GStreamer 101
yuvipanda
 
Ostinato FOSS.IN 2010
pstavirs
 
Raspberry Pi for IPRUG
Frank Carver
 
Flex pod driven by Openstack
Marton Kiss
 
CS 626 - March : Capsicum: Practical Capabilities for UNIX
ruchith
 
Packet crafting of2013
Shteryana Shopova
 
Software Packaging for Cross OS Distribution
Jian-Hong Pan
 
Asynchronous IO in Rust - Enrico Risa - Codemotion Rome 2017
Codemotion
 
Pipework: Software-Defined Network for Containers and Docker
Jérôme Petazzoni
 
A Kernel of Truth: Intrusion Detection and Attestation with eBPF
oholiab
 
Shall we play a game?
IngridRivera36
 
Shall we play a game?
Maciej Lasyk
 
tokyotalk
Hiroshi Ono
 
LCA14: LCA14-412: GPGPU on ARM SoC session
Linaro
 
Introduction GStreamer
Shih-Yuan Lee
 
Introduction to Gstreamer
Rand Graham
 
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
Ravi Rajput
 
Spying on the Linux kernel for fun and profit
Andrea Righi
 

Similar to Hackersuli - Linux game hacking with LD_PRELOAD (20)

PPT
101 2.3 manage shared libraries
Acácio Oliveira
 
ODP
LD_PRELOAD Exploitation - DC9723
Iftach Ian Amit
 
PPT
2.3 manage shared libraries
Acácio Oliveira
 
PPT
101 2.3 manage shared libraries
Acácio Oliveira
 
ODP
Libraries
Ashwanth Selvam
 
PDF
Course 102: Lecture 22: Package Management
Ahmed El-Arabawy
 
PPT
Advanced c programming in Linux
Mohammad Golyani
 
PDF
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
PDF
Linux System Troubleshooting
Thomas Howard Uphill
 
PDF
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
Felipe Prado
 
PDF
Linker Wisdom
dmichelsen
 
PPT
Linux interview questions-ppt
Mayank Kumar
 
PDF
Embedded Operating System - Linux
Emertxe Information Technologies Pvt Ltd
 
ODP
Code Red Security
Amr Ali
 
PPT
From gcc to the autotools
Thierry Gayet
 
KEY
Time tested php with libtimemachine
Nick Galbreath
 
PDF
LinuxCon Japan 2010 suzaki
Kuniyasu Suzaki
 
PDF
Introduction to Free and Open Source Software - August 2005
Saleem Ansari
 
101 2.3 manage shared libraries
Acácio Oliveira
 
LD_PRELOAD Exploitation - DC9723
Iftach Ian Amit
 
2.3 manage shared libraries
Acácio Oliveira
 
101 2.3 manage shared libraries
Acácio Oliveira
 
Libraries
Ashwanth Selvam
 
Course 102: Lecture 22: Package Management
Ahmed El-Arabawy
 
Advanced c programming in Linux
Mohammad Golyani
 
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
Linux System Troubleshooting
Thomas Howard Uphill
 
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
Felipe Prado
 
Linker Wisdom
dmichelsen
 
Linux interview questions-ppt
Mayank Kumar
 
Embedded Operating System - Linux
Emertxe Information Technologies Pvt Ltd
 
Code Red Security
Amr Ali
 
From gcc to the autotools
Thierry Gayet
 
Time tested php with libtimemachine
Nick Galbreath
 
LinuxCon Japan 2010 suzaki
Kuniyasu Suzaki
 
Introduction to Free and Open Source Software - August 2005
Saleem Ansari
 

More from hackersuli (20)

PDF
[HUN][Hackersuli] Lila köpeny, fekete kalap, fehér kesztyű – avagy threat hun...
hackersuli
 
PPTX
HUN Hackersuli 2025 Jatekok megmokolasa csalo motorral
hackersuli
 
PDF
[HUN][Hackersuli]Android intentek - ne hagyd magad intentekkel tamadni
hackersuli
 
PDF
[HUN][Hackersuli] Haunted by bugs on a cybersecurity side-quest
hackersuli
 
PDF
[HUN]2025_HackerSuli_Meetup_Mesek_a_kript(ografi)abol.pdf
hackersuli
 
PPTX
[HUN] Unity alapú mobil játékok hekkelése
hackersuli
 
PPTX
Hackersuli_2024_LLM_prompt_injection.pptx
hackersuli
 
PPTX
[HUN][Hackersuli] Abusing Active Directory Certificate Services
hackersuli
 
PDF
ITBN - LLM prompt injection with Hackersuli
hackersuli
 
PPTX
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
PDF
[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon
hackersuli
 
PDF
2024_hackersuli_mobil_ios_android ______
hackersuli
 
PDF
[HUN[]Hackersuli] Hornyai Alex - Elliptikus görbék kriptográfiája
hackersuli
 
PPTX
[Hackersuli]Privacy on the blockchain
hackersuli
 
PPTX
[HUN] 2023_Hacker_Suli_Meetup_Cloud_DFIR_Alapok.pptx
hackersuli
 
PPTX
[Hackersuli][HUN] GSM halozatok hackelese
hackersuli
 
PDF
Hackersuli Minecraft hackeles kezdoknek
hackersuli
 
PDF
HUN Hackersuli - How to hack an airplane
hackersuli
 
PDF
[HUN][Hackersuli] Cryptocurrency scams
hackersuli
 
PPTX
[Hackersuli] [HUN] Windows a szereloaknan
hackersuli
 
[HUN][Hackersuli] Lila köpeny, fekete kalap, fehér kesztyű – avagy threat hun...
hackersuli
 
HUN Hackersuli 2025 Jatekok megmokolasa csalo motorral
hackersuli
 
[HUN][Hackersuli]Android intentek - ne hagyd magad intentekkel tamadni
hackersuli
 
[HUN][Hackersuli] Haunted by bugs on a cybersecurity side-quest
hackersuli
 
[HUN]2025_HackerSuli_Meetup_Mesek_a_kript(ografi)abol.pdf
hackersuli
 
[HUN] Unity alapú mobil játékok hekkelése
hackersuli
 
Hackersuli_2024_LLM_prompt_injection.pptx
hackersuli
 
[HUN][Hackersuli] Abusing Active Directory Certificate Services
hackersuli
 
ITBN - LLM prompt injection with Hackersuli
hackersuli
 
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
[Hackersuli] Élő szövet a fémvázon: Python és gépi tanulás a Zeek platformon
hackersuli
 
2024_hackersuli_mobil_ios_android ______
hackersuli
 
[HUN[]Hackersuli] Hornyai Alex - Elliptikus görbék kriptográfiája
hackersuli
 
[Hackersuli]Privacy on the blockchain
hackersuli
 
[HUN] 2023_Hacker_Suli_Meetup_Cloud_DFIR_Alapok.pptx
hackersuli
 
[Hackersuli][HUN] GSM halozatok hackelese
hackersuli
 
Hackersuli Minecraft hackeles kezdoknek
hackersuli
 
HUN Hackersuli - How to hack an airplane
hackersuli
 
[HUN][Hackersuli] Cryptocurrency scams
hackersuli
 
[Hackersuli] [HUN] Windows a szereloaknan
hackersuli
 

Recently uploaded (20)

PPTX
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
PDF
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
PPTX
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PDF
DevOps Design for different deployment options
henrymails
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPTX
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPTX
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
PPTX
internet básico presentacion es una red global
70965857
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
本科硕士学历佛罗里达大学毕业证(UF毕业证书)24小时在线办理
Taqyea
 
Azure_DevOps introduction for CI/CD and Agile
henrymails
 
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
DevOps Design for different deployment options
henrymails
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
Research Design - Report on seminar in thesis writing. PPTX
arvielobos1
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
internet básico presentacion es una red global
70965857
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 

Hackersuli - Linux game hacking with LD_PRELOAD