finding and reversing backdoors in consumer firmware · 2014-04-07 · finding and reversing...

27
Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? Craig Heffner Embedded Vulnerability Analyst for Tactical Network Solutions Embedded Device Exploitation instructor 2 The Internet of (Backdoored) Things 3

Upload: others

Post on 16-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Finding and Reversing Backdoors in Consumer Firmware

#eelive Produced by EE Times

Who Am I?

• Craig Heffner– Embedded Vulnerability Analyst for Tactical Network Solutions– Embedded Device Exploitation instructor

2

The Internet of (Backdoored) Things

3

Page 2: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Meet the Contestants

4

Tools For Code / Data Analysis

• strings, hexdump• The Interactive Disassembler (IDA)• GNU tool chains (objdump)• Others

– Radare2– Reverse Engineering Compiler– The Online Disassembler– Retargetable Decompiler

5

Firmware Image Analysis

6

Page 3: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

7

Existing Firmware Analysis Tools

• Just search for “magic” file signatures– UWFirmforce– Binary Analysis Tool– Hachoir– File / radare2 / libmagic

• Problems:– Few, if any, firmware specific signatures– Difficult to add / modify signatures– Prone to false positives / false negatives– Slow

8

Binwalk

• Easy to create / modify signatures• Built-in false-positive detection• Automated, recursive extraction• Entropy / heuristic analysis• Fast

9

Page 4: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

10

11

12

Page 5: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

13

Trendnet TEW-654R

14

TEW-654R Features

• Travel router / access point / firewall• Three operational modes:

– WiFi Access Point– WiFi Client– WiFi Router

15

Page 6: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Binwalk Analysis

16

/etc/rc.d/rcS

17

tftp /etc/resolv.conf

18

Page 7: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

19

strings system_manager

20

tftp get /etc/rt.db

21

Page 8: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

sqlite3 rt.db

22

Owned.

23

Vendor Response (TEW-632BRP)

• “Can’t reproduce.”• “That file doesn’t exist.”• “You can’t get the configuration file over TFTP.”• “But it doesn’t show up in a port scan!”

24

Page 9: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Post-Mortem

• One developer implementing a debug / recovery TFTP service– It’s OK for the TFTP service to listen on all interfaces– The firewall will block connections from the WAN

• Another developer implementing firewall rules– The only running UDP services are DNS and DHCP – Easier to just open all UDP ports on the firewall

25

D-Link DIR-100

26

DIR-100 Features

• SOHO router• Easy to set up• “Total network security”

27

Page 10: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Binwalk Analysis

28

strings /bin/webs

29

“thttpd-alphanetworks/2.23”

30

Page 11: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

/bin/webs Function Listing

31

alpha_auth_check

alpha_auth_check Disassembly

32

xmlset_roodkcableoj28840ybtidexmlset_editby04882joelbackdoor

alpha_auth_check Pseudo Code

if(strstr(struct->ptr, “xmlset_roodkcableoj28840ybtide”) != NULL){ return AUTH_OK;}else{ return check_login();}

33

???

Page 12: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

alpha_auth_check Call Graph

34

alpha_httpd_parse_request Disassembly

35

alpha_httpd_parse_request Pseudo Code

if(strncasecmp(header, “User-Agent:”, 11) != NULL){ struct->ptr = header + 11 + strspn(header, “ \t”);}

36

struct->ptr = HTTP User Agent

Page 13: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

alpha_auth_check Pseudo Code

if(strstr(struct->ptr, “xmlset_roodkcableoj28840ybtide”) != NULL){ return AUTH_OK;}else{ return check_login();}

37

???

alpha_auth_check Pseudo Code

if(strstr(user_agent, “xmlset_roodkcableoj28840ybtide”) != NULL){ return AUTH_OK;}else{ return check_login();}

38

Google Chrome Spoof User Agent

39

Page 14: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Owned.

40

Vendor Response

• “Updates will be available October 31st.”

41

Post-Mortem

• “Some services need to change configuration settings automatically”• “The web server already has all the code for changing config settings”• “Let’s put a backdoor in the web server so our local services can

automatically change configuration settings without knowing the administrative password!”

42

Page 15: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

3SVision N5072

43

N5072 Features

• Outdoor weather proof camera• 720p @ 30fps• 18X optical zoom

44

Restricted Firmware Download

45

Page 16: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Use the Source, Luke

46

Literacy FTW

47

Binwalk Analysis

48

Page 17: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

/home/3s/bin/httpd

49

pwdgrp_get_userinfo

50

51

Page 18: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Hardest. Exploit. Ever.

52

Owned.

53

Vendor Response

• Vulnerability publically released July 2013• Crickets.

54

Page 19: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Post-Mortem

• Developer debugging?• Remote assistance / recovery

55

Tenda W302R

56

W302R Features

• 802.11n WiFi router• High gain antennas• Supports WiFi Protected Setup

57

Page 20: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Binwalk Analysis

58

Binwalk Analysis

59

Binwalk Analysis

60

Page 21: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

strings /bin/httpd

61

GoAhead-Webs

Hmmm...InitMfgTask?

62

InitMfgTask

void InitMfgTask(void){ pthread_create(&pthread NULL, MfgThread, NULL);}

63

Page 22: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

MfgThread

64

MfgThread

• Binds to a UDP socket listening on port 7329• Waits for an incoming packet from a client• Validates packet structure, performs requested action• Returns action result to the client

65

MfgThread Packet Structure

66

w302r_mfg\x00

e | 1 | x

<action_arg>

Page 23: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

MfgThread Command ‘x’

popen(action_arg, “r”);

67

popen result returned to client!

MfgThread Command Execution Packet

w302r_mfg\x00x/bin/ls

68

Owned.

69

Page 24: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Practical Exploitation

• Only listens on the LAN / WLAN• What if the user has configured wireless encryption?

70

WEP?

• Easily broken in a couple of minutes

71

WPA?

• TKIP attacks allow packet injection (~15 minutes)• AES is secure if a strong passphrase is used

– Unless...

72

Page 25: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

73

Vendor Response

74

75

Page 26: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Post-Mortem

• Manufacturing backdoor for testing / validation• Vendor considers LAN exploits “no big security problem”

– WiFi hot spots?– Users with weak / no WiFi encryption?– Unforeseen WiFi encryption attacks (e.g., WEP, TKIP, WPS)?

76

Conclusion

77

Q & A

78

Page 27: Finding and Reversing Backdoors in Consumer Firmware · 2014-04-07 · Finding and Reversing Backdoors in Consumer Firmware #eelive Produced by EE Times Who Am I? • Craig Heffner

Contact & Resources

[email protected]• @devttys0

• http://www.edetraining.com• http://www.tacnetsol.com• http://www.reaversystems.com

• http://www.binwalk.org• http://www.devttys0.com/blog

79