We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

NetRipper: Smart Traffic Sniffing for Penetration Testers

00:00

Formal Metadata

Title
NetRipper: Smart Traffic Sniffing for Penetration Testers
Title of Series
Number of Parts
109
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
The post-exploitation activities in a penetration test can be challenging if the tester has low-privileges on a fully patched, well configured Windows machine. This work presents a technique for helping the tester to find useful information by sniffing network traffic of the applications on the compromised machine, despite his low-privileged rights. Furthermore, the encrypted traffic is also captured before being sent to the encryption layer, thus all traffic (clear-text and encrypted) can be sniffed. The implementation of this technique is a tool called NetRipper which uses API hooking to do the actions mentioned above and which has been especially designed to be used in penetration tests, but the concept can also be used to monitor network traffic of employees or to analyze a malicious application. Speaker Bio Ionut works as a Senior Security Consultant at KPMG in Romania. He is passionate about ASM, reverse engineering, shellcode and exploit development and he has a MCTS Windows Internals certification. He spoke at various security conferences in Romania like: Defcamp, OWASP local meetings and others and also at the yearly Hacknet KPMG international conference in Helsinki and Berlin. Ionut is also the main administrator of the biggest Romanian IT security community: rstforums.com and he writes technical articles on a blog initiated by a passionate team: securitycafe.ro. Twitter: @NytroRST
32
Thumbnail
45:07
Demo (music)PasswordComputer networkEncryptionProcess (computing)Open setRead-only memoryWritingSystem callStructural loadMiniDiscModul <Datentyp>Function (mathematics)Computer-generated imagerySpacetimeLaptopSystem administratorMultiplication signModule (mathematics)Process (computing)Physical systemProjective planeCryptographyInformation securityBootingEncryptionFunctional (mathematics)Order (biology)Exploit (computer security)Semiconductor memoryRippingEmailReflection (mathematics)System callWeightHookingStructural loadMiniDiscType theoryInjektivitätBitElectronic mailing listServer (computing)BlogLink (knot theory)Block (periodic table)Cartesian coordinate systemWindowContent (media)Latent heatTrailCache (computing)Integrated development environmentSoftware testingSheaf (mathematics)PlastikkarteLibrary (computing)Touch typingUniform resource locatorAntivirus softwareSoftwareMereologyMultiplicationSet (mathematics)Medical imagingCodeOcean currentDirectory serviceInformation technology consultingClassical physicsDemo (music)WritingMessage passingGoodness of fitAsynchronous Transfer ModeRemote procedure callLevel (video gaming)Object (grammar)Flash memoryCASE <Informatik>Thread (computing)Address spaceComputer animation
Structural loadComputer-generated imageryFunction (mathematics)System callComputer networkAddress spaceHacker (term)InformationFirefox <Programm>CompilerFunctional (mathematics)Order (biology)Flash memorySystem callCodeSheaf (mathematics)HookingMultiplication signInformationSource codeProper mapBootingResource allocationUniform resource locatorData structurePoint (geometry)Address spaceDebuggerPrototypeParameter (computer programming)Term (mathematics)Computer fileCASE <Informatik>outputPointer (computer programming)Medical imagingWindowReading (process)EncryptionAdditionMiniDiscMereologyClassical physicsRight angleCartesian coordinate systemSemiconductor memoryDistanceSoftwareEmailElectronic signatureVideo gameApplication service providerRippingProcess (computing)Core dumpSelectivity (electronic)WebsiteComputer animation
Graphical user interfaceNetwork switching subsystemPointer (computer programming)Binary fileString (computer science)Plug-in (computing)Limit (category theory)Module (mathematics)System administratorDemo (music)Graphical user interfaceWebsiteWindowString (computer science)Order (biology)Computer fileError messageReading (process)Functional (mathematics)Plug-in (computing)WritingSystem callMessage passingUniform resource locatorRevision controlCodeConfiguration spaceSemiconductor memoryStreaming mediaMaxima and minimaSlide ruleComputer configurationTable (information)Instance (computer science)Set (mathematics)Sheaf (mathematics)Proper mapProcess (computing)RippingWordDemo (music)Electronic visual displayPointer (computer programming)Arithmetic meanIdentity managementModule (mathematics)Data structureVirtual machineCartesian coordinate systemHookingWeightPasswordElectronic signatureLimit (category theory)PrototypeStructural loadSource codeLibrary (computing)Line (geometry)Attribute grammarInformation securityOpen setInformationSoftware testingMacro (computer science)Medical imagingExploit (computer security)SoftwareInternet forumUniqueness quantificationParameter (computer programming)Intrusion detection systemService (economics)BitDefault (computer science)Computer animation
Computer animation
Software testingVirtual machineComputer animation
Exploit (computer security)Module (mathematics)System administratorProcess (computing)Computer animation
FlagProcess (computing)Latent heatModule (mathematics)Computer animationSource code
Line (geometry)Configuration spaceComputer animation
Heat transferComputer fileConfiguration spaceDatabaseQuery languageComputer animation
FacebookSQL Server 7.0Connected spaceServer (computing)DatabaseQuery languageComputer animation
Computer animation
FacebookFacebookServer (computing)LoginPublic key certificateComputer animation
Public key certificateData loggerRippingDirectory serviceLocal ringComputer fileTap (transformer)Computer animation
Process (computing)String (computer science)ResultantComputer fileRippingOrder (biology)Moment (mathematics)EmailFunctional (mathematics)Plug-in (computing)Source codeComputer animation
SynchronizationClient (computing)Query languageHash functionString (computer science)Graphical user interfaceMessage passingComputer animation
Process (computing)String (computer science)Computer fileInformationContext awarenessFacebookReading (process)Content (media)Cartesian coordinate systemPasswordServer (computing)Query languageMessage passingRevision controlWritingEncryptionData managementHookingHash functionRootComputer animation
Computer fileInformationContent (media)Server (computing)Plug-in (computing)Computer animation
Cartesian coordinate systemAntivirus softwareSemiconductor memoryOperator (mathematics)Process (computing)Content (media)PasswordInformationFacebookLoginComputer animation
Module (mathematics)Exploit (computer security)Source codeInjektivitätServer (computing)Computer filePasswordInformationData managementQuery languageComputer animation
Demo (music)PasswordEncryptionProcess (computing)WritingRead-only memorySystem callStructural loadMiniDiscFunction (mathematics)Graphical user interfaceLimit (category theory)SoftwareRegulärer Ausdruck <Textverarbeitung>Physical systemInformationLatent heatSpherical capComputer networkSoftwareUsabilityOnline helpInformationCartesian coordinate systemFunctional (mathematics)InjektivitätBinary codeHookingExploit (computer security)Antivirus softwareReflection (mathematics)Order (biology)Regulärer Ausdruck <Textverarbeitung>Semiconductor memoryRevision controlSource codeOperating systemLatent heatProcess (computing)Module (mathematics)Computer animation
InformationComputer animation
Transcript: English(auto-generated)
Good afternoon, everyone. First and foremost, a little bit of housekeeping. If anyone has lost a pair of sunglasses and can describe them to me, come see me. Otherwise, I have a new set of sunglasses and thank you for that. Next up, I just want to point out that if you're looking for seats because you're coming in, there are seats up here in the front and there's some to the side as well. Now, we are in track 3 for net ripper,
smart traffic sniffing for penetration testers. Without further ado, I give you Yannes Popescu. Got it. All right. Cool. Hi, everyone. First of all, a bit about me. I'm Yannes Popescu. I'm
from Romania and I work as a senior security consultant at KPMG Romania. Also, I'm a blogger at securitycafe.ro and the administrator of the biggest security community from
Eastern Europe. A few things about my country. It's located in Eastern Europe. It's a country of Dracula. We have the first Olympics. We invented the jet plane and we have probably the most beautiful girls in the world. Don't trust me. Come and check. Here
is the agenda, what we're going to talk about. An introduction about this tool. A few details about how it works. Some details about the reflective DLL injection. The API
hooking. Some hooking examples. Demo and hopefully everything will be okay. The introduction. What is net ripper? Net ripper is a post exploitation tool for Windows systems that captures the network traffic even if it is encrypted or not. It captures the
traffic before it is encrypted or after it is decrypted at the application layer by injecting a DLL and using API hooking and hooking specific functions. The most
important thing about this is that it works without an administrator. It works for a low privileged user. Here is the main scenario. In our projects we encountered this situation multiple times. We had access to administrator laptops and we didn't know what to do to
pivot to the other servers. So this is where the idea came from. This is the general example of how it works. Let's say for outlook. Someone writes an email. The email is
encrypted and the encrypted data is sent through the network. So the user layer is where the user types the email. The network layer contains the encrypted data and net ripper is
injected at the encryption layer. Here is an example. The user writes the email. For this example is for outlook. Outlook uses encrypt that DLL in order to encrypt and decrypt
the data. The data is then sent encrypted after with the send or WSA send Windows API functions. It hooks this function from encrypt that DLL and it gets the data before it is
encrypted. This also happens for the decryption. It hooks the SSL decrypted packet and after the data is decrypted by the SSL decrypted packet function it can access the
plain text data. This is the main idea. I use the reflective DLL injection to inject the DLL. API hooking to hook specific functions and save the data locally. This is how
classic DLL injection works. The application opens the remote process. It writes in the process memory the full DLL, the full path of the DLL in the process memory and call library to load the DLL. So the library will load the DLL into the process memory. But
this has some disadvantages. The DLL must be written on this and the antivirus can pick them and the DLL is listed in the process modules. The reflective DLL injection was implemented by the security and this is how it works. The DLL contents are copied the
full DLL content is copied into the target process memory. However, the DLL doesn't look the same in the process memory like on the disk. So it has to auto load itself
correctly. For this, the reflective DLL injection uses a function called reflective loader. This function does all the steps necessary to correctly load the DLL. The advantages of this method is that the DLL doesn't touch the disk. So you can easily
bypass the antivirus. And that the DLL is not listed in the process modules. Because it's not loaded with the library and the window system use the process environment block to keep a link to the list with all process modules. I hope you can read this.
This is first step for the DLL injection. This is actually the injection of the DLL using
reflective DLL injection. If you can see, there's a method called a function called get the reflective loader offset. This function just searches the reflective loader functions and returns the offset in the DLL. After this step, we allocate space in the
target process memory with the full size of the DLL. The DLL is now written with the process memory function. And we call using create remote thread, the reflective
loader function. This code, actually reflective DLL injection code is from Stephen. After this function is called, what it does is to search for the image base of
the process. Actually, it searches where the DLL is mapped in the memory. It searches for the windows portable executable header. So it starts from the current location and searches for the header. After it finds the header, it needs to know some functions
required to properly load itself into memory. So it finds functions like load library, get address, virtual log and instruction cache. Next step is to load the DLL headers and
sections in a new location. The section must be aligned in memory, so this step is required. It's not difficult to parse the PE, the portable executable headers. So it
just parts the PE header and get each section and map it into a place of memory. After the sections are loaded, the next step is to process the imports. You may create a DLL
that uses specific DLL from windows. In order to make sure everything will work, you have to make sure every DLL is loaded into memory. Every imported DLL is loaded into memory. So what it does is to parse the data directory, the directory imports. The directory imports
is a location in the PE header that describes each DLL that should be loaded in order to make sure the DLL is loaded properly. Those things are automatically done by the windows PE loader. But we want to avoid using it. Next step is to process the image allocation.
Image location are some addresses that are directly pushed on the stack or directly used in the code. For example, if you have a push location, this location has to be relocated
in case of the DLL is not loaded at the required memory location. Each PE file DLL or executable have a preferred image base, but at least for the DLLs, it may happen to load
the DLL at another location. So this is required. After the DLL is completely loaded into memory correctly, it just needs to call the main function of the DLL. The main function is
DLL main for DLLs. Okay. API hooking. We take the same example with Outlook and encrypt that DLL. So we want to redirect the packet to our hooking function. So we will
redirect the function from encrypt that DLL to that DLL. These are the steps that we have to follow in order to do this. We have to find the function address and this in some cases may be the difficult part. We place a call instruction right at the beginning
of the function and we call a generic hooking function instead. We restore the original bytes because we modified them. Call a call back function, a function that process the data from our target function. In this case, SSL encrypt packet. And in that function, we
have the plain text data. We save data to a file and then restore the hook for additional calls. This is the normal assembly for a function. As you can see, it starts with a mo VDI and the classic function push EBP, mo VBP, ESP. After we hooked this
function, first five bytes are replaced by our call. Call and that specific address. That address is actually the address of our generic hooking function. A few details about how
this work. This is how we place the hook. We create a call instruction. The code for the call instruction is E8. And we calculate the distance between the original function and
our call back function. Our hooking function. And we save the original bytes in order to restore them later. Flash instruction cache, actually I'm not sure if it is strictly required on Windows because it doesn't seem to do anything. Here is our generic hooking
function. Every time we place a hook, we call this function. And this is how it works. First of all, we have a hook structure. In this structure, we save the call back address, our function, the original address, the address that we hooked, the original bytes
and the call bytes. If you can see, an important thing about call and not jump is that call automatically pushes on the stick the next instruction. What we have to do is to
subtract 5 from that return address. And we have the original address of the hook function. So we can just iterate to all hooks and find the structure for that specific hook. The
hooker gets hooked by original address. Do this for us. After we find the hook structure, we can access the original address and the original bytes. So we can call
memcpi in order to restore the original bytes. So the function is now not hooked and it is like original function. After we restore the original bytes, what we have to do is to call our call back function. Our call back function saves the data and restores the hook.
We have all the required information in that structure. This is how a call back function works. It must have the same prototype and also must specify the calling
convention. When API is using STD call, some other functions use calling convention. And what it does is to write to a temporary file the unencrypted data. The packet wants to
encrypt the data. The data is specified by the PP input parameter and the data size is specified by CB input parameter. So after the data is saved, we call the original function. So make sure the data is correctly sent to the network. And we restore the
hook. For example, for Mozilla Firefox and some other applications, we find the DLLs that encrypt and decrypt the data and send it to the network. Those are NSS3.DLL and NSPR
that DLL. We find the PR read and PR write functions and hook them. So PR receive and PR send may be used by some other applications. Another useful example would be putty. A lot of people use putty. So this is going to be useful. Adriaan Fortuna, my colleague from
KPMG Romania, wrote a really cool tool called putty rider that does the same thing. It hooks some functions, L disk send and term data. L disk send will send each character and
term data will be called with the received data in order to be displayed on putty. Putty rider can do a lot of other things. So you may take a look at it. Adriaan wrote the
signatures, actually the first byte of the functions in order to find the function. So I just find the code section from putty.ixie. And I search those functions and hook them.
For win SCP, also really used in real life, I found this way to compile the source code. I was able to compile it. It also took me some time to find the correct functions because there are a lot of functions. But I found in SSH.C the functions that looks to send
the network traffic before it is encrypted or to decrypt the traffic. So we have just to find the send receive functions. We place an interrupt 03 that will break point in the
debugger, compile the application and run. And see the data in the debugger. Those are the functions used by win STP. SSH packet send have a parameter called PKT that structure that
contains the data and the data size. And the SSH 2 will return a packet structure that will contain the pointer to the data and the data size. This is how the send and receive functions look like. And I had to just copy the first byte of each function and search it
in the code section. So I was able to hook them and find their location. The main problem is that not all the applications use a DLL in order to call some functions to
encrypt and decrypt the data. And the win STP is one of these tools. They are statically linked with some different libraries and it may be really difficult to find the correct function and the function prototype to be able to hook them. So this is the
code that hooks the win STP send and receive functions. Like putty I created signatures for these functions. And I searched the process memory for these functions and place our hook. Chrome maybe I think it may be difficult to compile Chrome. I didn't try to
do this. Instead I used some ideas from some underground forums. And this can be more complicated than it looks like. Chrome uses a table called SSL methods where the SSL
functions are set. So we have to find that SSL method structure that contains the SSL read and SSL write functions. In the source code of Chrome, this is for Chrome NSS. Until version 37, Chrome used NSS. NSS is the security services from Mozilla. After some
problems, they wanted to change to open SSL. But with open SSL, there are also a lot of problems and they decided to create their own work of open SSL. So in the code of NSS, you
can find a function called SSL setup IO methods. This will call the get default EO methods. However, we have to find the start of the SSL methods pointer. And in order to
find this, we rely on the PR declared attribute which have the value four. So we find
the call of the function by searching the SSL string as you can see in the SSL init IO layer. There's a method called PR get unique identity with a parameter called SSL. We find that string on the data section of the executable and we can find the call
of this function. Then we find the call for the setup IO methods where we can find the SSL methods table. So after we found the SSL string, we find the call of the
method that sets the SSL methods. And highlighted with red in bottom right, you can see a value of four attributed to a location. That is the location of an SSL table and we use that table to find the SSL functions. This is the code. We find the string into the
process memory. And we find that specific method. And using that specific method, we are able to find the SSL functions. Then starting with version 38, chrome uses a fork of
open SSL called boarding SSL. Also it's statically linked and all functions are available in chrome.dll. And in order to find the correct functions, we rely on the
error message that was available in both SSL functions. This string is specified by the open SSL put error macro. So the DLL will contain in the data section a string that
contains the compiled file. So we search in the data section this string. That's called the CW. And so on. And we have to find the correct call of the function. There are
about 20 calls with this string. So we have to find the 15 and the 17 location. Those are the SSL functions. This is the code that search the specific string in the data
section. And it search for the 17 and 15 location of that string. So we are able to find the SSL sent and read functions. I thought it might be useful to create some
plug-ins for this tool that will process the both sent and received data. There are only three plug-ins but I hope they are useful. The plain text specifies if we
want to save only the plain text data or to send all the data. The data limit is used to avoid large log files and we set the maximum file request size. And the string finder is a plug-in that will write in a specific file some new lines, some strings that
we can specify there. So for example, if the data contains the word pass, we can log in another file. The plain text plug-in may be useful in order to avoid large amount of
data within an image file. That's not our interest. The data limit may be used to trim the data and save only the first 4,000 bytes of the data. And the string finder can find
our words in the data. In this example, it finds the password and the log in information for a specific account. The net ripper has two components. The windows module
that can configure the DLL and inject the DLL. The DLL configurations mean just to specify specific values for the plug-ins. To specify if you want plain text or not. Specify the data limit or find in the request some strings using the string finder
plug-in. And you can also test to use it to inject the DLL in a specific process. Like in this example, we inject the DLL in Firefox. This can be useful in order to test some specific application. For example, you are not a penetration tester. You don't want to
pivot to the network but you want to find what the application is sending through the network. So it may be useful to analyze such applications. And down you can see an example with Firefox. Here is the module. It is a post exploitation module so we need to
have access to the compromise machine. And there are the same configuration options like in the windows module. We have to specify values for the string finder plain text and data limit plug-ins. The data path represents where to save the data. The string temp will
automatically detect the local temporary folder. And we can specify either the process IDs or the process names where we want to inject the DLL. Now for the demo, I have
two virtual machines. One with Kali Linux, the penetration tester machine. And the other one windows 7 64 bit. And this will be the victim. Just a moment. Yeah, I'm not sure if
you can see. Yeah, it works now. Okay. Okay. We should have a meterpreter session. And I
have access to our victim machine. This will be the pen tester and this will be the victim. So it is a normal user. And we will use the post exploitation module. We just
have to inject this in specific processes. Here is the example list. And run. Yeah, sorry. I
have to run. And the module will inject the DLL in all processes with specific process
names. And let's take some examples. For example, it can use putty and do some stuff. It
can use the win SCP. And let's say it will modify a file. A configuration file. The
transfer is not complete. Just wait to send the modified file. Okay. It can connect to MySQL database. And it can execute a query. It can search some data on Skype or talk to
someone. It can use Yahoo messenger. This was really used in Romania. It can use SQL
server to connect to a database. And execute some queries. It can use FileZilla. And
send an e-mail. It may browse some secure server. Or even from Facebook login to an
account also on SSL. An important advantage of this method is this one. The certificate is your certificate. So someone may look at the certificate and may not be sure that if
everything is okay. Okay. And now the attacker. What it has to do, it has to download the
log file specified in the local directory. This is in C. Users. Local user. APP data. Local.
And tap. Here it will create a folder called net reaper. And here should be all the files. We just download all of them. Each file contains the process ID, the process name and the
function used in order to capture the data. This may be useful because the processes may also the net reaper can also catch both the encrypted data and the data before it is encrypted. So you may have some junk data there. You have to filter the results. Just a
moment to finish the execution. The string finder plugin creates those files and then specifies the string finder. Okay. Now we have the files. Let's see what we have.
The MySQL client received some data. And we executed the select from MySQL user which
contains the hash of the admin. This may be useful. The data sent and our query. The
string finder finds our strings and one of them is password. And this contains the hash of the user. For chrome, we may find useful information in SSL read and SSL write
functions. And SSL write. Those are for the plain text. So we may not find really
useful information here. Putty, this is what putty received. And you can see the contents of
the file here. And this is what putty sent. So we can find the user name and the root password. The receive and send don't contain any useful information. Also string finder found some useful information for us. We also send and receive will not contain useful
information. But the SSH packet sent will contain the contents of the modified file. And the packet will also contain the file from the server. So everything is plain text. For
Firefox, it is used to read the information. You can see some junk information there
because a lot of content is compressed. And here are the Facebook requests. And here is the login information we are searching for. The user name and the password. For the
SQL server management studio, we can also find some queries automatically executed. And
the data received. You may find new things about the SQL server using this. And for file zero, the whole traffic is plain text. And you can find all the information here.
Here is the send data. So the user name and the password. The tool is not complete.
I want to make it support 64 processes. And to support a lot of applications. And
even older versions of the applications. The hook is also not thread safe. So I have to work on this. And I also want a regular expression. For the defense, I think this is a Microsoft operating system issue. But, for example, my Kaspersky actually warns me if an
application tries to modify the process memory of another application. And I think all antiviruses should do this. Here is the project. It's private now, but in a few minutes I will make it public. So we will have the source code, binaries and metasploit module.
As a conclusion, this is a post exploitation tool. It uses reflective injection and API hooking and hook specific functions that encrypt and decrypt the data in order to capture the network in plain text. And it should be easy to use. If you have any
questions, I can't hear you. Oh, okay. It doesn't work now. I will make it public in a
few minutes. And here is my contact information if you need help or if you have
suggestions or everything else. Thank you.