Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Feature meterp sniffer wpcap #173

Closed

Conversation

sempervictus
Copy link

Convert sniffer to use WinPCAP instead of PSSDK. Allows community members to build their own sniffers, and more. See commit messages for details and test output.

RageLtMan added 3 commits June 25, 2015 16:35
This begins the process of removing PSSDK components and migrating
meterpreter to a common PCAP based interface for host-resident
network operations.

Current state:
1. Remove PSSDK related functions and definitions from sniffer
2. Use directives to ensure platform-specific calls are used by the
compiler when needed - thread creation being a good example.
3. Update common.h with a DEBUGTRACE_FILENAME definition and file
output for real_dprintf if its defined.
4. Update CaptureJob struct for OS-specific implementation.
5. Misc cleanup
6. Operational Summary:
  Dispatcher commands work - start, stop, stats, interfaces.
  Sniffer seems to hang after 4 packets are collected in the
buffer.
  WinPCAP needs to be in the deps submodule to compile
  WinPCAP must be installed on the host to run (for now)
  Testing done with winpcap 4.1.3

Todo:
1. Stabilize sniffer_handler and thread, document in detail.
2. Finalize sniffer functionality on winpcap with separately
installed winpcap DLLs and driver.
3. Link all required DLL functions into the sniffer DLL specific
to the architecture in use.
4. Extract the silent pcap installer's registry-related operations
and drivers, implement registry ops and driver drop/remove in the
extension itself (now with DLL components linked in). Use a flag to
determine if winpcap was previously there, preferably link to the
host's db notes, and clean up as appropriate (instantly once we
init the driver would be ideal, post process acceptable).
5. Create a metpcap library to abstract common functionality for
PCAP related ops and OS-specific abstractions. Implement things
like pcap dispatch threads, callback handlers, and basic structs
here for reference by whats coming next, and all community work
subsequent to that.
6. Convert sniffer to use libmetpcap as test case, iron out bugs.
7. The fun part...
Convert use of POSIX LOCK to CRITICAL_SECTION under windows.
Implement functional abstractions for lock_* functions to CS calls.

Remove debug kill of the job's active status in the sniffer_thread
loop - was causing the 4 packet capture scenarios.
Working sniffer binaries on PCAP for Win32 and Win64.

Test output:
```
[*] Starting interaction with 79...

meterpreter > load sniffer
Loading extension sniffer...success.
meterpreter > sniffer_start 1
[*] Capture started on interface 1 (50000 packet buffer)
meterpreter > sniffer_stats 1
[*] Capture statistics for interface 1
	packets: 4
	bytes: 444
meterpreter > sniffer_stats 1
[*] Capture statistics for interface 1
	packets: 9
	bytes: 1112
meterpreter > sniffer_stats 1
[*] Capture statistics for interface 1
	packets: 14
	bytes: 1780
meterpreter > sniffer_stats 1
[*] Capture statistics for interface 1
	packets: 19
	bytes: 2448
meterpreter > sniffer_stop 1
[*] Capture stopped on interface 1
[*] There are 26 packets (3200 bytes) remaining
[*] Download or release them using 'sniffer_dump' or ...
meterpreter > sniffer_dump 1 /tmp/sniffer.pcap
[*] Flushing packet capture buffer for interface 1...
[*] Flushed 26 packets (3720 bytes)
[*] Downloaded 100% (3720/3720)...
[*] Download completed, converting to PCAP...
[*] PCAP file written to /tmp/sniffer.pcap
meterpreter > exit
[*] Shutting down Meterpreter...
```

File output for /tmp/sniffer.pcap:
```
/tmp/sniffer.pcap: tcpdump capture file (big-endian) - version 2.4
(Ethernet, capture length 65536)
```

tshark -r shows proper traffic recorded

---------------------------------------

TODO:
1. Link all DLL functionality from winpcap directly into the dlls.
2. Create in-line driver installer to work directly from sniffer.
2a. Check for presense of wpcap, set WPCAP_INSTALL flag if missing
2b. Create entries for each existing NIC in registry to be hooked
2c. Drop OS and architecture appropriate driver into windows
2d. Init the driver and NIC, if WPCAP_INSTALL is set, cleanup.
2e. Cleanup should remove any reg entries added by ext and npf.sys
3. Export functionality required to use PCAP/WinPCAP to libmetpcap.
3a. Device enumeration using PCAP interfaces + native OS info
3b. PCAPJob struct (CaptureJob today) for holding data and threads.
3c. Concurrency abstractions - MUTEX/CS pieces, threading, safety.
3d. Default PCAP thread handlers for reading and writing data
3e. Section 2 components for Windows side of the house.
3f. Convert Sniffer (and others) to use the new library interfaces.
4. Resurrect old community extensions which make use of PCAP
5. Port/build things atop the new common interface.
@metasploit-public-bot
Copy link

Can one of the admins verify this patch? For more information see: https://github.com/rapid7/meterpreter/wiki/CI-Testing

@OJ
Copy link
Contributor

OJ commented Jun 25, 2015 via email

@bcook-r7
Copy link
Contributor

We'll need to also incorporate winpcap's libs and headers into the windows build process I presume. That would probably mean an addition to the meterpreter-deps repo, like we do for openssl.

@sempervictus
Copy link
Author

The updated sniffer extension already expects winpcap to be here (in deps/winpcap), i'd obviously appreciate any extra testing, but i believe it should build as is on the windows side.

@sempervictus
Copy link
Author

Looks like i broke the POSIX side pretty badly.
@bcook-r7, @OJ : could you guys take a look at what i broke? Seems some of my declarations dont add up on the POSIX side.

@OJ
Copy link
Contributor

OJ commented Jun 26, 2015

@sempervictus it could be that the build isn't picking up the deps properly. I'll have a poke shortly.

@sempervictus
Copy link
Author

The POSIX side already has all the deps it needs, and i'm failing the build locally as well on 14.04. I can spin up a build host later, but i'm elbow deep in a stack of documentation.

@OJ
Copy link
Contributor

OJ commented Jun 26, 2015

Ah ok mate, no worries.

@hsluoyz
Copy link

hsluoyz commented Jun 8, 2016

Hi.

You would like to try Npcap: https://github.com/nmap/npcap.

It's another fork of WinPcap with multiple new features.

@sempervictus
Copy link
Author

We did, I think the momentum behind opening up all extensions may have
fizzled though or the timing of this PR against the migration to payloads
repo left it behind. Would love to see it fixed for POSIX and in full review
On Jun 8, 2016 09:43, "Yang Luo" notifications@github.com wrote:

Hi.

You would like to try Npcap: https://github.com/nmap/npcap.

It's another fork of WinPcap with multiple new features.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#173 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABRPjMuXUqE-35Syfd-7ocZd7ORwkhFwks5qJscVgaJpZM4FMKGe
.

@bcook-r7
Copy link
Contributor

bcook-r7 commented Jul 2, 2016

It more-or-less got left behind, but definitely still interested if someone wants to rebase this on the new repo!

@bcook-r7
Copy link
Contributor

bcook-r7 commented Jul 2, 2016

cc @wwebb-r7

@wwebb-r7
Copy link

@bcook-r7 started seriously looking into it as of today

@busterb
Copy link
Member

busterb commented Jun 11, 2020

Closing this out since this repo is dead.

@busterb busterb closed this Jun 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants