This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Zeerg/v0.3.2
V0.3.2
- Loading branch information
Showing
8 changed files
with
50 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,35 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
"encoding/hex" | ||
"os" | ||
|
||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/pcap" | ||
|
||
"golang.org/x/net/icmp" | ||
"reflect" | ||
"log" | ||
"bytes" | ||
) | ||
|
||
var ( | ||
captureDevice string = "eth0" | ||
ipListen string = "0.0.0.0" | ||
captureTime int32 = 1024 | ||
promiscuous bool = false | ||
err error | ||
timeout time.Duration = 1 * time.Second | ||
handle *pcap.Handle | ||
filter string = "icmp" | ||
) | ||
|
||
// pingReassemble takes the payload and reassembles it. | ||
func pingReassemble(outFile, captureDevice string, captureTime int32) { | ||
|
||
// Open device | ||
handle, err = pcap.OpenLive(captureDevice, captureTime, promiscuous, timeout) | ||
check(err) | ||
defer handle.Close() | ||
|
||
// Set filter | ||
err = handle.SetBPFFilter(filter) | ||
// pingListen waits for the ping at the address | ||
func pingListen(outFile, ipListen string, captureTime int32) { | ||
// Listen for ping | ||
pkt, err := icmp.ListenPacket("ip4:1", ipListen) | ||
check(err) | ||
packetSource := gopacket.NewPacketSource(handle, handle.LinkType()) | ||
for packet := range packetSource.Packets() { | ||
appLayer := packet.ApplicationLayer(); | ||
payload, err := hex.DecodeString(string(appLayer.Payload())) | ||
check(err) | ||
fmt.Println(string(payload)) | ||
f, err := os.OpenFile(outFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||
// Wait to get request | ||
for { | ||
buf := make([]byte, 1024) | ||
_, addr, _ := pkt.ReadFrom(buf) | ||
clientAddr := addr | ||
m, err := icmp.ParseMessage(1,buf) | ||
check(err) | ||
defer f.Close() | ||
if _, err := f.WriteString(string(payload)); err != nil { | ||
check(err) | ||
} | ||
} | ||
|
||
} | ||
datBody := reflect.ValueOf(m.Body).Elem().FieldByName("Data").Bytes() | ||
b := bytes.Trim(datBody, "\x00") | ||
decodedText := hexDecode(b) | ||
log.Println(decodedText) | ||
log.Println(clientAddr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters