Share E-Book

Practical Hardware Pentesting, 2nd edition (Early Release) (Jean Georges Valle)(Z-Library)

Author

Rating 3.5 AI initial rating

Log in to rate

Cybersecurity
Language English

Practical Hardware Pentesting Second Edition is an example-driven guide that will help you plan attacks hack your embedded devices and secure the hardware infrastructure. Throughout the book you ll explore the functional and security aspects of a device and learn how a system senses and communicates with the outside world. You ll set up a lab from scratch and gradually work towards an advanced hardware lab. The first part of this book will get you attacking the software of an embedded device. This will get you thinking from an attacker point of view; you ll understand how devices are attacked compromised and how you can harden a device against the most common hardware attack vectors. As you progress you ll get to grips with the global architecture of an embedded system and sniff on-board traffic learn how to identify and formalize threats to the embedded system and understand its relationship with its ecosystem. This 2nd Edition covers real-world examples featuring various devices like smart TVs baby monitors or pacemakers you ll discover how to analyze hardware and locate its possible vulnerabilities before going on to explore firmware dumping analysis and exploitation. By the end of this book you ll and understand how to implement best practices to secure your hardware

Format PDF
Size 5.1 MB
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
Contents 1. Practical Hardware Pentesting Second Edition Learn attack and defense techniques for embedded systems in IoT and other devices 2. Feedback 3. Prerequisites the basics you will need 4. Approach to buying test equipment 5. The component pantry 6. Sample labs 7. Summary 8. Questions 9. Feedback 10. Technical requirements 11. Introduction to the boards 12. Why C and not Arduino 13. The toolchain 14. Introduction to C 15. Summary 16. Questions 17. Further reading 18. Feedback 19. Technical requirements 20. Understanding I2C 21. Understanding SPI 22. Understanding UART 23. Understanding D1W 24. Summary 25. Questions 26. Feedback 27. Technical requirements 28. Finding the data 29. Extracting the data 30. Understanding unknown storage structures 31. Mounting filesystems 32. Repacking 33. Summary
Page 3
34. Questions 35. Further reading
Page 4
Practical Hardware Pentesting, Second Edition: Learn attack and defense techniques for embedded systems in IoT and other devices Welcome to Packt Early Access . We’re giving you an exclusive preview of this book before it goes on sale. It can take many months to write a book, but our authors have cutting-edge information to share with you today. Early Access gives you an insight into the latest developments by making chapter drafts available. The chapters may be a little rough around the edges right now, but our authors will update them over time. You can dip in and out of this book or follow along from start to finish; Early Access is designed to be flexible. We hope you enjoy getting to know more about the process of writing a Packt book. 1. Chapter 1: Setting Up Your Pentesting Lab and Ensuring Lab Safety 2. Chapter 2: Our Main Attack Platform 3. Chapter 3: Sniffing and Attacking the Most Common Protocols 4. Chapter 4: Extracting and Manipulating Onboard Storage 5. Chapter 5: Attacking Wi-Fi, Bluetooth, and BLE 6. Chapter 6: Software-Defined Radio Attacks 7. Chapter 7: Accessing the Debug Interfaces 8. Chapter 8: Static Reverse Engineering and Analysis 9. Chapter 9: Dynamic Reverse Engineering 10. Chapter 10: Scoring and Reporting Your Vulnerabilities 11. Chapter 11: Understanding Your Target 12. Chapter 12: Identifying the Components of Your Target 13. Chapter 13: Approaching and Planning the Test 14. Chapter 14: Wrapping It Up – Mitigations and Good Practices
Page 5
Feedback We are constantly looking at improving our content, so what could be better than listening to what you as a reader have to say? Your feedback is important to us and we will do our best to incorporate it. Could you take two mins to fill out the feedback form for this book and let us know what your thoughts are about it? Here's the link: https://packt.link/HardwarePentesting2E . Thank you in advance. Embedded systems, in the broadest definition of the term, are all around us in our everyday lives (examples being our phones, our routers, our watches, our microwaves, and more). They all have a small computer inside them and take care of very critical aspects of our lives, and also collect and protect data that is very critical to us. Sadly, the embedded system industry is lagging behind the usual computing industry in terms of security. In the last 10 years, we have seen examples of how this lack of security in these kinds of systems can lead to very tangible impacts on the real world (for example, the Mirai botnet; a slew of viruses targeting the industrial world’s embedded systems across a large number of vendors (stuxnet, darkenergy, industroyer, pipedream/incontroller, etc.) ; a wave of attacks against routers; some countries stealing other countries' drones by spoofing the Global Positioning System ( GPS ); and so on). This is why it is very important to train more and more people on how to find problems in these kinds of systems, not only because the problems are already here but also because there will be more and more such systems, and their ever-growing number will manage more and more crucial aspects of our lives (think about autonomous vehicles; drone delivery; robots to assist the elderly; and so on). Helping you start with assessing the security of these kinds of systems is the first goal of this book. The second goal of this book is that you have fun while you learn because testing these kinds of systems is going to be interesting, and I take great pleasure in making the learning process enjoyable for you. You may ask yourself: How is it going to be fun for me? For me, it is
Page 6
because you are messing with the most trusted part of the system: the hardware. Not only you are messing with the most fundamental elements of the system, but you also are in direct contact with it; you will be soldering, drilling, scrapping, and touching the system to pop a shell! You will not only code to compromise your target system, but (hopefully rarely) the blood, sweat, and tears will not be figurative! In this chapter, you will learn how to set up your lab, from a simple, low investment suitable for learning at home up to a professional testing environment. This chapter will get you up to speed on how to invest your money efficiently to achieve results and, most importantly, how not to kill yourself on the job. The following topics will be covered in this chapter: The basic things you will need to get started The different types of (common) tools available for your labs, what to get, and at which point The approach to acquiring test equipment, and the difference between a company and a home lab Basic items you will want in a lab, what they are, what are their uses, and the approach to setting up a lab Examples of ramping up your lab: basic, medium, and professional labs
Page 7
Prerequisites – the basics you will need Before going into the things you will need to buy, let's have a look at the basics you will need to go through our joint exploration of an unknown system (a Furby), and start working on your own systems. Languages To be able to script activities and interact automatically with most systems, you will need to be familiar with at least one high-level programming or scripting language (I will use Python for the examples in this book, but any other scripting language such as Perl, Bash, PowerShell, and more will also work) and one low-level programming language to write your own firmware and customize the examples. I will also use C (on the attack platform) since it is the most popular programming language for embedded systems, but any language that has a compiler for your target system will work. Hardware-related skills You will need to learn actual, manual skills that are not purely knowledge- based; the main obstacles people fear when starting hardware hacking are soldering and understanding of basic electronics concepts. For both of these skills, you can approach them in a knowledge-based way: learn about Ohm's law; the physics of semiconductors; what is an eutectic mixture and temperature; and all of the theoretical background. To be honest, I would not recommend approaching these skills like that. Of course, you may need the knowledge down the road, but don't start with this. Solder things; make light-emitting diodes ( LEDs ) blink; learn how to use transistors as switches. In short: do things, accept failure, and learn from it; burning a transistor will cost you a few cents but you will not repeat your error; burning your fingers will hurt but this will heal in a few days (there are
Page 8
safety instructions in the book—read them very carefully). You have far more chances to lose your motivation by learning a lot of laws and formulas while never using them than by having a problem, finding the correct formula, and solving your problem with it! System configuration Having a nice desktop computer will really improve your experience in the lab. Even if, in today's world, people tend to use laptops more and more, this can prove to be a challenge when you are attacking hardware. A laptop will not block you from attacking hardware, but a desktop will definitely make your life a lot easier. A laptop's main challenge will be the very limited physical interfaces available on it (still, you can work with it). You don't need a powerful computer to start with (I use a 7-year-old i7: nothing fancy), but really pay attention to the interfaces. It is very common for me to use 5-6 Universal Serial Bus ( USB ) ports when I am attacking hardware; for example, when operating on any embedded system, I typically have the following things attached to my computer (not even counting my convenience peripherals such as keyboard, mouse, headset, having a dual- screen setup, and so on): USB: - A bus pirate - An OpenBench logic analyzer - One or two USB to Universal Asynchronous Receiver/Transmitter ( UART ) bridges - A microcontroller unit ( MCU ) board - A function generator - My programmable power supply Ethernet: - My internet connection - My oscilloscope Good luck doing that with a laptop without using an external USB hub,
Page 9
especially when these hubs can interfere with the functionality of some peripherals (for example, the USB-UART bridges I use tend to become unstable if used over a USB hub—using a good-quality powered USB hub can help). One of the main contention points is the operating system. I use Linux, but using a Windows-based machine (especially if you use the Windows Subsystem for Linux ( WSL ) for anything but access hardware peripherals) will not really limit you in the end. (I will base the examples in this book on Linux. If you don't want to install a machine with Linux, just run a virtual machine ( VM ) but be aware that some of the most popular and free virtualization software do not really support USB passthrough very well.) Setting up a general lab The setup of the lab itself is very important and will be quite determinant in terms of your ease of use and comfort in the lab. You will spend a lot of hours thinking and hacking in there, thus the room and its furniture will be quite important to your comfort. You will need to consider the following factors: Your chair : Invest in a good wheeled desk chair with easily movable arm support and good back and lumbar support. The race car seat- looking chairs targeted at gamers can be a good type to look into, but really pay attention to the armrests and the system that allows you to move them out of the way and set them to the desired height easily. More often than not, they will annoy you when using your soldering iron, but you will want them to support your arms when typing, for example. Your work table : Three factors are critical—the height of the table (so you don't kill your back when operating close to a printed circuit board ( PCB ), for example) and its surface. For the surface, I like clear colors (to be able to easily see a component that slipped, for example) with a slightly textured surface (so the components don't skid too far too easily). Also, the larger your work surface, the better it is to spread the inevitable clutter. Shelving : You will want to have shelving on top of your work table in
Page 10
order to be able to have your instruments on top of your work area without them eating up the space available. I like to have the shelving approximately 50 cm higher than the surface of my work table in order to be able to easily manipulate the interface of the instruments and put back probes without having to stand up from my chair nor having to kill my neck when I look at waveforms or a specific knob or button. Light : Good and powerful lighting of your work area is crucial; not only you will be manipulating a variety of very small things (components, cables, connectors, and others), but it becomes even more important when operating under magnification (for example, for soldering). Pay attention to the intensity of your light but also its color temperature (more blue or more yellow, I prefer a balances 5000K daylight-like temperature), keeping in light that the bluer it is the higher the risks of it disturbing your sleep cycle. Anti-static measures : An anti-static mat is really practical to protect sensitive devices against electrostatic discharge. They come with a bracelet that ensures any electrostatic charge you may have built up is dissipated. It is also important to avoid flooring that will make you build up such charges (such as carpets). Soldering mat: Cheap silicon soldering mats can be bought for cheap on online stores. Get one, they avoid part slipping away easily and usually have integrated small sorting bins that are really usefull. Safety There are inherent risks linked with opening and interacting with live systems. Please read these carefully—safety first! Please follow these safety tips at all times: 1. If there is a risk of electric shock, never ever do your tests alone and be sure to brief the person who is with you on how to quickly kill the power and react. Have emergency services' number preeminently displayed; a fire extinguisher that can be used on live electricity; first aid training; and so on. 2. Whenever your fingers or instruments go near a system, ensure it is either disconnected from the mains (that is, wall plug electricity—
Page 11
110/220V (where V stands for volts )) or that you are physically isolated from the mains part of the board (for example, use silicon mats to isolate the dangerous part of the power section). 3. If a system is mains-powered, always, always use an insulation transformer. 4. Wear adequate clothing, remove jewelry and, if you are sporting long hair, always tie this up (which will prevent it from getting in the way). 5. If the system sports any kind of battery, insulate the battery rails appropriately (with electrically insulating sticky tape, for example). Some battery types are dangerous and can catch fire or explode if shorted. I really advise you to have a look at videos of shorted lithium- polymer batteries: you don't want this kind of catastrophic failure happening in your home, lab, or office. 6. You will work with sharp and hot tools and objects, so having a first aid kit available is always a good idea. 7. There is a debate about what is dangerous: voltage or current. Actually: energy kills, so both voltage and current can be dangerous. For example, you may have already survived a > 10 kilovolt ( kV ) electric shock from electrostatic discharge (the sparks you can feel when removing a pullover, for example), but 2,000 A at 1 V will char you to death, and people regularly get killed by mains power. The gist is, whether amps or voltage are present, treat it as dangerous. 8. Soldering equipment is very hot and will set things on fire if you are not cautious; always have a smoke detector in your lab, along with a fire extinguisher. Use the holder your soldering iron comes with (or buy one); they are usually shrouded to avoid contact with random objects. Safety is of the utmost importance—there is no need for all the fancy test equipment we will now go through if there is no one left to operate it.
Page 12
Approach to buying test equipment These are my personal opinions and views. Especially regarding measurement equipment and tools, you will find a lot of heated argument about the different brands, models, and tools. Engineers tend to be reasonable but they are human beings, and there will be fanboys. You will find on different forums people with their opinions and the deeply rooted belief that what is working best for them is the best for anyone. The golden rule is the following: Get information upfront Make up your mind Be reasonable Get what works best for you Home lab versus company lab Some very important distinctions have to be made between your own personal laboratory equipment and what you use in a company laboratory. Not only will the money for the home lab come from your own pocket, but some options (such as renting) may not be realistic for a home lab. Additionally, a company lab is subject to the safety rules of a work environment. You should meet with your company's occupational safety manager in order to comply with the adequate regulations regarding the storage of hazardous or corrosive chemicals, ventilation/air extraction, handling of possible fire hazards, and so on (as a side note, this is a very practical and reasonable way to get out of this noisy open space we all love to hate). Hacked equipment and Chinese copies In a home lab, one of the best reminders of why you are doing the assessment is the fact that some instrument companies are suspected by the community of actually producing hackable instruments in order to boost their sales. And
Page 13
their instruments get hacked. This is a reminder that there is a very real community (and not a fabled hacker hidden in their parents' cellar) that is going after electronic devices in order to get the most out of them, unlocking features that are normally paid for, and potentially costing money to the company that produces the instruments. From a hobbyist point of view, it may be not really legal, but it is a common practice for hobbyists to maximize their investment by modifying or hacking existing instruments. Since legality and repeatability are key in a company laboratory, I would advise against hacking instruments in this context. If the current laboratory setup of your company is not enabling a test to take place, your company should have a budget to buy (or rent) the adequate instruments or be able to offset the cost to a client. The same goes for Chinese copies of programmers and logic analyzers—you may not care about it in a private setting, but in a professional setting the lower quality can actually turn back to bite you. The gist is, as long as you are doing this as a hobby, the decision to hack your instruments is on you, but if you are doing this professionally, buy the real thing and get reimbursed, or bill your client. Approaching instrument selection Measurement instruments are like cars; it's all a question of balance The Italian sports car type—the luxury thing that will be able to do everything (short of cooking for you), which costs an insane amount of money and actually very few people can get the most out of. It may not be worth it in an assessment context unless you have a really specific need. If it is the case, it may be smarter to just rent the instrument. Brands that I classify in this category: Teledyne-LeCroy, Rohde & Schwartz, and high-end Keysight (formerly Agilent). The good-quality German car that is doing everything quite well. It may be a good investment if you are actually doing this a lot and need a reliable, solid instrument that will get you far for a long time. Brands that I classify in this category: mid-range Keysight, Tektronix, Yokogawa, and very high-end Siglent or Rigol.
Page 14
Le French car type—it's going to be doing almost the same thing that the German car does, for a fraction of the price, with a lot less style, and maybe for a shorter time. Brands that I classify in this category: mid- range Siglent or Rigol. The no-frills, cheap Japanese car—it's going to be efficient and cheap, get you from point A to point B, but you're not going to get a lot out of it on the speedway. Brands that I classify in this category: low-range Siglent or Rigol. The "el cheapo" Chinese car. It is cheap; it's a box with an engine and a driving wheel, but not much more. Also, don't have a crash in it: its safety is not so well engineered. Brands that I classify in this category: OWON. And just as with a car, you can find very interesting second-hand deals! Don't underestimate second-hand instruments—a lot of renting companies sell their used equipment second-hand, and you can score pretty sweet deals like that. (My first oscilloscope was a second-hand 100 MHz-bandwidth Phillips, which I scored on eBay and used for 3 years without a problem.) What to buy, what it does, and when to buy it Here is a table of the main types of different instruments, what they are used for, and how much they are needed (0 being the highest priority): Instrument Description Priority Digital multimeter (DMM) A DMM is a fundamental tool that allows you to measure voltage, resistance, and current intensity and also to check for continuity. Advanced models allow you to measure other values such as frequency, inductance, and capacitance. 0
Page 15
Soldering iron Just as with the DMM, a soldering iron is one of the pieces of equipment you will use the most. Directly go for a temperature-controlled one. This will allow you to make your own circuits, remove and exchange components, and more. 0 Bus pirate This is a very useful multi-tool to interact with in-circuit buses- more on it in the in- circuit communication chapter: Chapter 6 , Sniffing and Attacking the Most Common Protocols . 0 Logic analyzer A logic analyzer reads digital protocols and allows you to decode them in software later. This is extremely useful for spying on inter-chip communication, developing and debugging your custom tools, and more. 1 An MCU platform you will get to know well and will learn to use efficiently. This will be
Page 16
MCU platform very useful to send fake messages on buses, impersonate a chip, and pretty much interact programmatically with the target system's electric signals. We will go for a cheap and flexible one (the blue pill) later in the book. 1 JTAG adapter JTAG (named after the Joint Test Action Group) is historically an interface to test the soldering of chips. It has been extended to offer chip-specific programming and debug interfaces and functions. 1 Oscilloscope An oscilloscope allows you to measure voltage in function of time and trace the curve of this voltage. Current models can do additional measurements (frequency measurement, frequency spectrum, and more), trace voltages in function of another, decode digital protocols, and so on. 2 A hot air station is an advanced version of a soldering iron. It is very practical to work with
Page 17
Hot air station surface-mounted components since it will allow you to heat all leads and underlying pads of a component at once. 2 Lab power supply Lab power supply comes in two main flavors: variable ones (where you can set a fixed output voltage and a maximum current limit manually) and programmable ones (where you can set the voltage and current limit programmatically). The first kind is all you need to start and do most of your work. The programmable ones are more advanced and, should you need one, you'll be knowledgeable enough to know it. I personally only have a manual one and have never needed a programmable one. 0 (var) / 3(prog) FPGA platform A field-programmable gate array (FPGA) is a programmable logic platform that allows you to do really fast and high throughput operations. This piece of equipment is among the more 4
Page 18
advanced that you should look into when you have become more familiar with procedural programming or if you have a specific need to do something really fast. DMM The DMM is your principal tool—you will be using it all the time. I really mean all DMM basics Your DMM will come with a manual. Read it. Even if you have used a multimeter before, you have to know the basic characteristics of the tool you will be using. If you have never used a multimeter, it should come with at least these functions: Voltage measure : This will measure the voltage difference between the two test leads. If your DMM doesn't have an auto-range function (like most entry-level meters), you will have to set the measuring range and set it to direct or alternating voltage. Current measure : This will measure the current (the amount of electricity) passing through the leads. Again, pay attention to the range. Most of the time, you will have to change the connector one of the leads is plugged into (from V to A; sometimes there is even a mA connector for lower ranges). Resistance measure : This will measure the resistance between leads by creating a known voltage between the leads and measuring the current that the resistance lets go through. Again, pay attention to the range. The resistance is inferred by using Ohm's law: Voltage (in volts: V) = Resistance (in Ohms: Ω) x Current (in amperes: A).
Page 19
Continuity test : When the test leads are connected with a negligible resistance, the multimeter will beep. A fast continuity test will really make your life easier and a slow response continuity beep is a very common downside of very cheap DMMs. TIP Never use the continuity measurement or resistance measurement modes on a live circuit—not only can the reading be false but you can also damage your DMM! Getting your workhorse You will be able to find a curated list of DMMs with their characteristics and comparison on the EEVblog forum. (I also warmly encourage you to watch the videos from EEVblog—Dave Jones' style isn't for everybody, but I personally like it a lot and his videos are always very educative.) The list can be found here: https://www.eevblog.com/forum/testgear/multimeter-spreadsheet/ . I really don't recommend going for a very cheap Chinese DMM, nor can I point you toward an exact model since it may not be valid in a few months. The elements to pay attention to when selecting a DMM (in order of priority) are the following: The DMM really should be of a safety rating compatible with what you are measuring (at least CAT III, as you will be measuring main voltages at some point) and the probes should be really sharp. In a worst-case scenario, you can always buy replacement probes. Bandwidth, precision (the number of displayed digits), and the count numbers should be as high as your budget allows. The speed of the continuity test (try to find review videos)—you want it to be as fast as possible. The available ranges—you really want as wide a range of measurement as possible, both of alternating current ( AC ) and direct current ( DC ) (it should range from millivolts to at least 1,000 volts; from a few
Page 20
ohms to a few dozens of megaohms; and from a few microamps to 10 or 20 amps for current). The input impedance (that is, the capability of the meter to read the voltage from a circuit without disturbing the circuit)—you want at the very least 10 megaohms (the higher the better). A serviceable fuse that you can replace easily. Good back-lighting to help with screen visibility when you are working late. The battery lifetime is also a common default that plagues the cheap chinese DMMs, having to stop your test to run to the closest shop to buy batteries can be annoying. Soldering tools Get a good temperature-controlled soldering iron with widely available replacement tips. Again, it is desirable to have a good workhorse and a lower- quality secondary iron (you will very rapidly be confronted with the necessity to rework surface mount parts; it is often tricky with a single iron and very often results in damaged PCB pads). The temperature control is very important since you will be confronted with leaded and unleaded solder, which have a different melting temperature; different-sized components with their own thermal mass (that is, how much heat does the component source from your iron before getting hot); and so on (get both irons with temperature control; the secondary doesn't need to be as precise as the main one). Some additional supplies are also extremely useful, as listed here: Liquid and tacky flux : This allows the melted solder to flow much more easily on the leads and pads. You will be constantly removing and re-soldering parts from PCBs, and flux will be helping you tremendously, especially for su rface-mounted device ( SMD ) parts. I am partial to Kingbo RMA-218 for tacky flux. Soldering wick : This is an invaluable tool to remove excess solder and clean PCB pads before soldering back a part. I was always kind of disappointed with solder wick… until the day I met chemtronic’s solderwick. The best one around, end of story. Fluxed, leaded solder : Get two different thicknesses, one in the 0.5 mm range and the other one as thin as you can get for SMD rework. You
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List