Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
143 views
Debugging Zine
Computer, Programming, Debugging, Independent publisher, Free
Uploaded by
lowtec
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Debugging Zine For Later
Download
Save
Save Debugging Zine For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
143 views
Debugging Zine
Computer, Programming, Debugging, Independent publisher, Free
Uploaded by
lowtec
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Debugging Zine For Later
Carousel Previous
Carousel Next
Save
Save Debugging Zine For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 20
Search
Fullscreen
Teen 10 oF | you'll QD : MS 2, cee Ce uae tcpdump! A SMALL ° “ard HaNdBO0k FOR ANYON WHOWRITES (OR RUNSII) PROGRAMS ON Linux COMPUTERS BY: JULIA EVANSwhat's this? Hil This is me: Juua Evans blog: jyns. cad twitter:@bOrk and in this zine I want to tell you about how I qot better at debugging These are 5 ways I've changed how L think about debugging. j Remember the bug is happening fora logical reason. THs never magic. Really. Even when it makes no sense. 3 J {be confident L can fix it {ERD this Ewell Ive fixed before: (Be alot of hacd bugs before G Talk to my coworkers gEA know my debugging toolkit before: Now: ZI want to know S$ THING bet L don't Know how to Fiad out G most im 5) C5 : LT learned to like et before: fhe) about to leam SN facial expression: determination Some thing T can't teach you in 20 pages to y debugging (though Til try anywayt) LT can show you some of my debugging toolkit though | These are the tools L reach for when I have A question about a program I want to Know the answer to. By the end of this, L hope +o have given you a few new tools to use!Section L: I/O and x System calls & Hello, dear reader In this zine, there are 3% sections of tools that I love. For each tool, I'll tell yeu why it's useful and give an example. Each one is either i) Some of the most basic questions you might have when you log into a mis behaving machine are: - is this machine writing to ar reading $rom disk? The network? - are the programs reading Files? Which Files? So, we're starting with Finding out which resources are being used and what our programs are doing. Let's golNX — = tat | o dstat |= T love dstat because it's Super simple, Every second, ut prints out how much network and disk your computer used that second. @ Once Lhod an intermittent! slow database server. I opened up dstat and stared at the out put while monitoring database speed. I$ dstat_| send |recv during this period, sk everything is normal ° 300 MB DATARASE 43 MB GETS SLow é 3 back to norma Could 340MB coming in over the network Mean... a 30OMB database query}! ZyEsve This wos an AWESOME CLUE that helped us isolate the problem query,Vistrace} 17 (chove a SO ey sticker on™ P os) Ls my favourite program. Tt peints every system call your program used. Tt's & cool way to get an overall picture of what your PrOgram Ts doin ,and LY using ct to answer questions like “which Files are being apened? . ~ C 1g strace e python my_program. Py | A oe ceo open("/home/bork/ .config_file") = 3 gue read(3, “the contents of the file”) ~ hundeeds of lines. F (connects, "172.217.0.163") & \sendto(S, “hi!!") WARNING strace can make your program run $0x slower. Don't run it on your Production database TL can't do justice to strace here, but I have Q whole other zine aboutit at jvns.ca/zinesopensnoop ¥ eBPFX (kind of) When you run ‘Spensnoop p {PID | T will print out every File being opened by a program. You might think 20/7 Strace can do this tool Sust use strace -e open -P $PIO and you would be right. But Strace can make Uour program run 10x slower. Opensnoop won't slow you down, = how to get ite Requires : Ubuntu 16.64 + or a ~4.4+ Kernel version = how it works = Opensnoop is & script thot uses a new kernel Installation instructions at: Feels ae SeePr 3 : github. com / iovisor /bec. eBPFis Fas There's also an opensnoap on OSX& gspl That one is powered by DTrace. Shere are. lots of eBPE- powered Foals¥ Check out Shak GitHub cepo to \earn more!Wh OE fase, section 1:8 networking 8 “447 ps ot Tve devoted a lot of space inthis zine to networking tools, and I want to explain why. A \ot of the programs L work with communicate over HTTP. response request mm GET 7) Pan far {name traf” Ieots /42." program colour: “blue” Every programming language uses the same network protocols So the network iS a nice language -inde pendent place ta Answer questions like: * Was the request wrong , or was tt the response? aS my service even running ? *my program is slow. Whose Fault is that ? Let 's 96 vHTTP requests are fundamental really simple — they're gust text! To see that, let's make one by handY First, make a File: request. tat! _ i 1 \ { Host: ask.metofilter.com ' { User-Agent + zine 1 ( (2 new \ines! important |!) ‘ ioe —_—- sr Then: nc stands for netcat ! § cat request. txt nc metafilter.com 80 e back with a bunch etcat to send am \ ‘ You should get a respons: of HT™L | You can also use 1 huge Files over a local network quickly: step: (on target machine) step 2: (on the source) 4 eee ' $ hostname -L \ , . 1 192.168.2.132 «= 1! cat bigfile | \ ne 192.168. 2.132 91934} V ne -£ 9931 7 bigfile i} 's this \istens on the pot! this sends the data ) a“ Spo-z-& netstat feceive a request, a program (aka" server’) needs to be’ listening’ on the port. Finding out which Programs are Listening on which ports is really, easy . Its gest Every network request gets sent to oO port (like $0) ona computer. To xe < & ‘ tuna, please Y "ye whe og —— alse known os _ (Sudo netstat -tunapl Here's what you'll sees ~ proto —local_address PID / program name tcp 0.0.0.0 8353 2993 / python port ? So! L & netstat because it tells me which processes are cunning on which ports. On 0S X , use | lsof -i-P instead.narep ismy favourite starter network spy tool | Try it right now! Run: sudo ngrep -d any metafilter | \ Then go to http:// metafilter. com in youe browser. You should see matching network packets in ngrep’s output T We are SPIES Y Recently at work T’d made a chang @ To a client so that it sent {*some-id “>... 3 with all its requests. I wanted +o make sure iF was working, so TL ran: —_-— —_--T —_ “ ; sudo ngrep some-id Z - ~~ -—- > - ~~ — TI found out that everything was ok vbGe tcpdump u cpdump is the most difficult networking tool we'll discuss here and it took mea while to y ct. T use it to save network traffic to analyze later | “port 8977" is 7T7T actually ating sudo tcpdump poct 38997 \ Program inthe 1 -W service. | | “Berkeley Packet Lae ca Filter” (BPF) rT language. BPF oT *) isthe] | Filfers get compited a Pcap File’ C packet capture") ise and thes ron really, Standard for saving network troSFfic. Everything understands prap & fast { Some situations where Tl use tcpdump: *T'm Sending arequest to amachine and T want to know whether it's even getting there, ( _tepdump port & 1 will peint every packet on port 80) * Thave some slow network connections and T want +o know whether to blame the client or Server. (we'll also need wireshark!) * I just want to print aut packets +o see them (tcpdump -A)wireshack Wireshark isan GUL +too\ For network analysis. Here's an exercise ta Qearn itY Run this: : sudo tcpdump port 80 -w hitp.peap ' While that 5 running, open metafilter. com in your browser. Then press CtrltC to stop tepdump. Now we havea pcap File to analyze! joocc ene eae eee Explore the Wireshark interface | Questions You can try te answer: © What HTTP headers did your browser send to metafilter.cam? Chint: search | Frame contains “GET"}) @® How long did the longest request take? Chint: click Statistics > Conversations ) ® How many packets were exchanged pt with metafilter.com's servers? |e nang (hint: search Vip. dat. 2 etafilter.comsection 3: CPU * Your programs spend a lot of time on the CPU! Billions oF cycles. What are they, DOING @! This section is atcut using spect 3 to answer that question. pecf is a Linux -onlu tool that is extremely useful and not as well -Known as it should be. Cin general, mu aim in this zine is to showcase tools that I think don't get enough love ¢) Some things I didnt have space For in this section but wanted to mentian ANYWAY * ryalgrind «the Sava ecosystem's fantastic tools (stack, Visual VM, Youck:4) which your language is probably jealous of * Ftrace (For linux kernel tracing) * Ltt (ditto) * eBPF9 pert y perfis not simple or elegant. Tt is a weird multitool that does a few different, very useful things. First, it's a Sam Ving /_ = \profiler/ = Try Funning : rot Tt st -- a a '§ sudo pect record python : “(press GNC after a f ew Second s) You can look at the results with: ‘$ sudo pect ceport 4s it spent S% of itS time in the Py Dict - GetItem function. Cool! We learned a Tiny thing about the CPythen interpreter. [orks everywhere 7] if you use pecf to profile a Python program, itll Mine SQ pect can be installed an pretty much any Linux Show you the C functions machine. The exact (symbols) from the CPython Features it has will interpreter, not the depend on Your Python fyactions . kernel version.pect is for everyone One dav, I had a secver that was Using 100% of its CPU.Within about 60 seconds, L knew it was doing reqular expression matching in Ruby | How ? ‘pect top’ is like top, but for functions instead of programs . ror ttTtaTT 1% sudo pect top process PID % Function perf top doesn't always help. + Ruby's internal rea, exp i Bot it's easy to try, and sometimes "7, Matchi function » T learn something ~ +++ especially Sava and node devs ' Remember when I said perf only know S C functions? It's not quite true. node.)S and the SVM (java, scala, clojure...) have bath taught peck about their functions. = [node] > | Sava| 2 | Use the Look up ‘pecf-map-agent -- pecf-basic-prof on GitHub ang follow Commard line. option the directionsSe RAR + Flame faphs are an awesome Wau, to visualize CPU performance, popularized by Brendan Grega's Flameg raph -pl tool. v 2 Qith.com /bendangegg / Flame graph 0 9 Here's whot they lock like: [ore mo% | [teeth 28% Panda 20% | alligator 80% Main 100% thousands) of stack traces sampled from A program. The one above means 0% of the stack traces started with © 4948 10% with banda 4 eat You can construct them fram ‘perf “recarding 5 (see Brendan Gegg's Flame graph github foc how) but lots of other unrelated tools can produce them too. 9 them. Main 4 alligatorSpy on your CPU tip: Google “Latency Numbers every Programmer Should lenow " Your CPU has a small cache on it (the LL cache \ that it can access in ~O.S nanosecond s | faster than RAM \ Tf you're trying, to da an apecation iA microseconds, CPU cache usage matters | Spec; Pow to | | pef stat Is | G use it lp eee eon fre statis Ire This runs ‘Js’ and prints a cepoct at the end. how do I know if mi program is Using ‘Pose caches @ POSS -e request ae p how it | Your CPU can track all kinds of counters Aworks | About what it's doing. ipecf stat! asks i+ +6 count things (like U 1 i d report the results. cache misses) L Hardware is cool Tye never used perf stat in eaenest but I think i4's awesome you can get SO much infe From your CPU.T hope you leaned Some thing new. Thanks for reading yg Thanks to my pactner kamal for help reviewing and to the amazin Monica Dinculescu C@not waldorf) for the cover art. To learn more, see: x my, blog - JYNS.CQ. x my other zines: Jvns.ca/2ines x brendangregg . com But really You just need ta experiment. Try, these tools everywhere. See where they help you track down bugs and where they don't. oop Strace reals, obthat didn't helped with tell me much, that problem ¥ oh well f Tt takes practice, but 1 find these tools both fun and a useful job skill. Z hope you will too flike this ? there are more Zines at: http ://jvns.ca/zines CC-BY-NC-SA Svlia Evans , wizard debugging industries
You might also like
How DNS Works
PDF
No ratings yet
How DNS Works
28 pages
Cyber Lab Manual 1
PDF
No ratings yet
Cyber Lab Manual 1
11 pages
Networking! ACK! - Julia Evans
PDF
No ratings yet
Networking! ACK! - Julia Evans
24 pages
IT-IAS02: Information Assurance and Security 2
PDF
100% (1)
IT-IAS02: Information Assurance and Security 2
46 pages
RTFM - Red Team Field Manual v3
PDF
100% (15)
RTFM - Red Team Field Manual v3
134 pages
Profiling & Tracing With Perf - Julia Evans
PDF
No ratings yet
Profiling & Tracing With Perf - Julia Evans
24 pages
Networking Zine PDF
PDF
No ratings yet
Networking Zine PDF
24 pages
A Few Things I'Ve Learned About Computer Networking - Julia Evans
PDF
No ratings yet
A Few Things I'Ve Learned About Computer Networking - Julia Evans
2 pages
Linux Debugging Tools
PDF
No ratings yet
Linux Debugging Tools
20 pages
CN Lab Record
PDF
No ratings yet
CN Lab Record
78 pages
Network Lab
PDF
No ratings yet
Network Lab
58 pages
NMT lab 4 _20-21
PDF
No ratings yet
NMT lab 4 _20-21
19 pages
Wireshark
PDF
No ratings yet
Wireshark
30 pages
CN Lab Manual
PDF
No ratings yet
CN Lab Manual
74 pages
Telnet
PDF
No ratings yet
Telnet
3 pages
cn prog 1
PDF
No ratings yet
cn prog 1
7 pages
EC8681 - Microprocessors and Microcontrollers Laboratory
PDF
No ratings yet
EC8681 - Microprocessors and Microcontrollers Laboratory
46 pages
Cs3591 Computer Networks Lab Mannual
PDF
No ratings yet
Cs3591 Computer Networks Lab Mannual
41 pages
4 Wireshark
PDF
No ratings yet
4 Wireshark
32 pages
Computer Networks Lab Record 2021(1) (1)
PDF
No ratings yet
Computer Networks Lab Record 2021(1) (1)
63 pages
AWS Interview Reviews
PDF
No ratings yet
AWS Interview Reviews
4 pages
V Cse Cs3591 Cn Labmanual
PDF
No ratings yet
V Cse Cs3591 Cn Labmanual
45 pages
Sniffing Network Traffic in Python
PDF
No ratings yet
Sniffing Network Traffic in Python
27 pages
1.3-Basic Packet Analysis Wireshark
PDF
No ratings yet
1.3-Basic Packet Analysis Wireshark
24 pages
V Cse Cs3591 CN Labmanual 1
PDF
No ratings yet
V Cse Cs3591 CN Labmanual 1
106 pages
NETSTAT Command: Netstat - A 1912077 - Myfile4
PDF
No ratings yet
NETSTAT Command: Netstat - A 1912077 - Myfile4
3 pages
Packet Capture
PDF
No ratings yet
Packet Capture
32 pages
Checkpoints Commands
PDF
No ratings yet
Checkpoints Commands
9 pages
Iii Cse CS8581 Networks Lab
PDF
No ratings yet
Iii Cse CS8581 Networks Lab
60 pages
CS3591 CN Lab Manual New
PDF
No ratings yet
CS3591 CN Lab Manual New
70 pages
Linux Networking Cheat Sheet
PDF
No ratings yet
Linux Networking Cheat Sheet
2 pages
Cs3581 CN Lab Manual Elakya
PDF
No ratings yet
Cs3581 CN Lab Manual Elakya
57 pages
Linux Ubuntu 12.04: Network Commands 2
PDF
No ratings yet
Linux Ubuntu 12.04: Network Commands 2
14 pages
10 Wireshark
PDF
No ratings yet
10 Wireshark
24 pages
Sanjay
PDF
No ratings yet
Sanjay
39 pages
RECORD
PDF
No ratings yet
RECORD
52 pages
Zumaroc Notes v2
PDF
No ratings yet
Zumaroc Notes v2
36 pages
RTFM - Red Team Field Manual
PDF
No ratings yet
RTFM - Red Team Field Manual
111 pages
RTFM - Red Team Field Manual PDF
PDF
100% (1)
RTFM - Red Team Field Manual PDF
111 pages
RTFM - Red Team Field Manual - Ben Clark
PDF
No ratings yet
RTFM - Red Team Field Manual - Ben Clark
134 pages
Network Configuration and Troubleshooting Commands
PDF
No ratings yet
Network Configuration and Troubleshooting Commands
44 pages
Network Security Lab Manual
PDF
100% (1)
Network Security Lab Manual
71 pages
Task 3
PDF
No ratings yet
Task 3
9 pages
Backtrack 1
PDF
No ratings yet
Backtrack 1
7 pages
Data Communication AND Networking Lab File: Birla Institute of Tecnology, Ranchi (Noida Campus)
PDF
No ratings yet
Data Communication AND Networking Lab File: Birla Institute of Tecnology, Ranchi (Noida Campus)
7 pages
Week 1 CN Lab
PDF
No ratings yet
Week 1 CN Lab
15 pages
Remote Monitoring System For Cyber Forensic
PDF
No ratings yet
Remote Monitoring System For Cyber Forensic
9 pages
Common Tools and Methods Used in Vulnhub CTF's
PDF
No ratings yet
Common Tools and Methods Used in Vulnhub CTF's
4 pages
Ethcial Hacking Lab Manual 2 (1)[1]
PDF
No ratings yet
Ethcial Hacking Lab Manual 2 (1)[1]
46 pages
Lab 5 Network Scanning
PDF
No ratings yet
Lab 5 Network Scanning
23 pages
Backtrack 1
PDF
No ratings yet
Backtrack 1
7 pages