Skip to content

Commit 2236e01

Browse files
committed
Link shellcode correctly
1 parent 22417da commit 2236e01

File tree

4 files changed

+39
-36
lines changed

4 files changed

+39
-36
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.*.swp
2+
Image
3+
zImage
4+
dtv_driver.ko
5+
threaddump.txt

Makefile

+31-22
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@ CROSS := arm-none-eabi-
1717

1818
RUN_CLI_DIR := /data/local/tmp
1919

20-
shellcode.o: shellcode.lds shellcode.S
21-
echo '.ascii "Built at $(shell date)"' > buildts.S
22-
$(CROSS)$(CC) $(CFLAGS) -nostdlib -o $@ $^
23-
24-
shellcode.bin: shellcode.o
25-
$(CROSS)$(OBJCOPY) -O binary -j .text --reverse-bytes=4 $< $@
26-
27-
shellcode.bin.h: shellcode.bin
28-
$(XXD) -i $^ > $@
29-
30-
shellcode.addr.h: shellcode.o
31-
$(READELF) -e $< | $(AWK) '/Entry point/ { print "tgt_addr_t shellcode_addr = "$$NF";" }' > $@
32-
33-
exploit: main.c shellcode.bin.h shellcode.addr.h
34-
$(CC) $(CFLAGS) -I$(CURDIR) -o $@ $<
35-
3620
decrypt: decrypt.c
3721
$(CC) $(CFLAGS) -o $@ $< -lcrypto
3822

@@ -49,24 +33,49 @@ threaddump.txt:
4933
threaddump.lds: threaddump.txt
5034
$(PERL) -nE 'say sprintf("%s = 0x%08x;", $$2, hex($$1)-hex($$3)) for /\[<(.*?)>\] \((.*?)\+0x(.*?)\//' < $< | sort -u | sort -k3 > $@
5135

36+
zImage:
5237
dtv_driver.ko:
5338
echo "Grab $@ from firmware dump (all copies are the same)"; exit 1
5439

55-
EXPECT_SYM=_Cust_dump_all_thread
40+
kernel.lds: zImage kernelutil
41+
./kernelutil -dump_symtab=$@ $<
42+
43+
MATCH_SYM=_Cust_dump_all_thread
5644
dtv_driver.lds: dtv_driver.ko threaddump.lds
5745
set -x; \
5846
vma=$$( $(CROSS)objdump -t dtv_driver.ko | \
59-
actual=$$($(PERL) -nE 'say $$1 if /^$(EXPECT_SYM) = (.*);/' < threaddump.lds) \
60-
$(PERL) -nE 'say sprintf("0x%08x", hex($$ENV{actual})-hex($$1)) if /(.*?) .*$(EXPECT_SYM)/' \
61-
); echo VMA: $$vma; if [ x"$$vma" = x ]; then echo $(EXPECT_SYM) not found, check $^; exit 1; fi; \
47+
actual=$$($(PERL) -nE 'say $$1 if /^$(MATCH_SYM) = (.*);/' < threaddump.lds) \
48+
$(PERL) -nE 'say sprintf("0x%08x", hex($$ENV{actual})-hex($$1)) if /(.*?) .*$(MATCH_SYM)/' \
49+
); echo VMA: $$vma; if [ x"$$vma" = x ]; then echo $(MATCH_SYM) not found, check $^; exit 1; fi; \
6250
$(CROSS)objdump --adjust-vma=$$vma -t dtv_driver.ko | \
63-
$(PERL) -nE 'say "$$2 = 0x$$1;" if /^(\S+)\s+g\s.*\s(\S+)$$/' | \
51+
$(PERL) -nE 'say "$$2 = 0x$$1;" if /^([0-9a-f]+)\s+.\s.*\s(\S+)$$/ && hex($$1) > 0' | \
6452
sort -k3 > $@
6553

54+
LOAD_SYM=_CmdVersion
55+
shellcode.lds: shellcode.lds.in dtv_driver.lds
56+
loadaddr=$$($(PERL) -nE 'say $$1 if /^$(LOAD_SYM) = (.*);/' < dtv_driver.lds) \
57+
$(PERL) -pe 's/#LOADADDR#/$$ENV{loadaddr}/g' < $< > $@
58+
59+
shellcode.o: shellcode.lds dtv_driver.lds kernel.lds shellcode.S
60+
echo '.ascii "Built at $(shell date)"' > buildts.S
61+
$(CROSS)$(CC) $(CFLAGS) -nostdlib -o $@ $^
62+
63+
shellcode.bin: shellcode.o
64+
$(CROSS)$(OBJCOPY) -O binary -j .text --reverse-bytes=4 $< $@
65+
66+
shellcode.bin.h: shellcode.bin
67+
$(XXD) -i $^ > $@
68+
69+
shellcode.addr.h: shellcode.o
70+
$(READELF) -e $< | $(AWK) '/Entry point/ { print "tgt_addr_t shellcode_addr = "$$NF";" }' > $@
71+
72+
exploit: main.c shellcode.bin.h shellcode.addr.h
73+
$(CC) $(CFLAGS) -I$(CURDIR) -o $@ $<
74+
6675
.PHONY: run-cli
6776
run-cli: cli
6877
$(ADB) push cli $(RUN_CLI_DIR)/cli && $(ADB) shell $(RUN_CLI_DIR)/cli $(CLICOMMAND)
6978

7079
.PHONY: clean
7180
clean:
72-
rm -f *.o *.bin *.bin.h *.addr.h buildts.S $(ALL_BINARY_TARGETS)
81+
rm -f *.o *.bin *.bin.h *.addr.h buildts.S *.lds $(ALL_BINARY_TARGETS)

shellcode.lds

-14
This file was deleted.

shellcode.lds.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SECTIONS {
2+
.text (#LOADADDR#) : ALIGN(0) { *(.text) }
3+
}

0 commit comments

Comments
 (0)