Skip to content

Commit 2c3dfb3

Browse files
committed
Add demo on GOT (and PLT) analysis
There are two source code files (`main.c` and `basket.c`), a header file (`basket.h`) and a `Makefile`. The `bascket.c` file will be compiled into a shared library (`libbasket.so`). The `main.c` will be compiled and linked against the shared library, resulting in an executable `main`. We investigate the resulting files: the `main` executable and the `libbasket.so` library. We used `nm`, `objdump` and `readelf` for static analysis and GDB for dynamic analysis.
1 parent 106d3ad commit 2c3dfb3

File tree

12 files changed

+530
-0
lines changed

12 files changed

+530
-0
lines changed

got-plt/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/main
2+
/libbasket.so

got-plt/Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CFLAGS = -fPIC -fno-stack-protector -Wall -Wextra
2+
LDFLAGS = -pie
3+
LDLIBS = -lbasket
4+
5+
.DEFAULT_GOAL := all
6+
7+
.PHONY: all clean
8+
9+
all: main
10+
11+
main: main.o libbasket.so
12+
$(CC) $(LDFLAGS) -Wl,-rpath=. -o $@ main.o -L. $(LDLIBS)
13+
14+
main.o: main.c basket.h
15+
16+
libbasket.so: basket.o
17+
$(CC) -shared -o $@ $^
18+
19+
basket.o: basket.c basket.h
20+
21+
clean:
22+
-rm -f basket.o main.o
23+
-rm -f main
24+
-rm -f libbasket.so
25+
-rm -f *~

got-plt/README.md

Lines changed: 419 additions & 0 deletions
Large diffs are not rendered by default.

got-plt/basket.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
unsigned long basket_size = 3;
2+
3+
void flowers(void)
4+
{
5+
basket_size = 55;
6+
}

got-plt/basket.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef BASKET_H_
2+
#define BASKET_H_ 1
3+
4+
extern unsigned long basket_size;
5+
6+
void flowers(void);
7+
8+
#endif

got-plt/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "basket.h"
2+
3+
int main(void)
4+
{
5+
flowers();
6+
basket_size = 99;
7+
8+
return 0;
9+
}

got-plt/nostdlib/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/main
2+
/libbasket.so

got-plt/nostdlib/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CFLAGS = -fPIC -fno-stack-protector -Wall -Wextra
2+
LDFLAGS = -nostdlib -nostdinc -pie
3+
LDLIBS = -lbasket
4+
LD.SO = /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
5+
6+
.DEFAULT_GOAL := all
7+
8+
.PHONY: all clean
9+
10+
all: main
11+
12+
main: start.o main.o libbasket.so
13+
$(LD) -e_start -pie -dynamic-linker=$(LD.SO) -rpath=. -o $@ start.o main.o -L. $(LDLIBS)
14+
# $(CC) $(LDFLAGS) -Wl,-e_start -o $@ start.o main.o -L. $(LDLIBS)
15+
16+
start.o: start.s
17+
18+
main.o: main.c basket.h
19+
20+
libbasket.so: basket.o
21+
$(LD) -shared -o $@ $^
22+
# $(CC) $(LDFLAGS) -shared -o $@ $^
23+
24+
basket.o: basket.c basket.h
25+
26+
clean:
27+
-rm -f start.o basket.o main.o
28+
-rm -f main
29+
-rm -f libbasket.so
30+
-rm -f *~

got-plt/nostdlib/basket.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../basket.c

got-plt/nostdlib/basket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../basket.h

0 commit comments

Comments
 (0)