Rozdělení tcpdump do více souborů

ATomas

Rozdělení tcpdump do více souborů
« kdy: 28. 07. 2015, 10:26:08 »
Zdravím,
omlouvám se, pokud jsem to napsal do špatné kategorie. Ale potřeboval bych pomoct s tcpdump
Loguji si přenos dat na mém serveru (linux debian 7) nějak takto:

Kód: [Vybrat]
tcpdump -n -e -i eth0 > /rec.txt
to bez problému funguje, ale má to jeden nedostatek, pokud loguji příliž dlouho, tak soubor je obrovský a je dost časově náročné ho otevřít a poté se v něm pohybovat. Proto bych potřeboval, aby tcpdump logoval do více souborů s menší velikostí. V manuálu jsem se dočetl že to údajně umí přepínač -w ovšem nevím jak to použít. Nemá s tím někdo zkušenosti ? Děkuji.
« Poslední změna: 28. 07. 2015, 12:54:11 od Petr Krčmář »


aaa158

  • ***
  • 238
    • Zobrazit profil
    • E-mail
Re:tcpdump
« Odpověď #1 kdy: 28. 07. 2015, 10:47:52 »
man tcpdump:
Kód: [Vybrat]
-w     Write the raw packets to file rather than parsing and printing them out.
-W     Used in conjunction with the -C option, this will limit the number of files created to the specified number, and begin overwriting files from the beginning, thus creating  a  ’rotating’  buffer.
-C     Before  writing  a  raw  packet to a savefile, check whether the file is currently larger than file_size and, if so, close the current savefile and open a new one.  Savefiles after the first savefile
              will have the name specified with the -w flag, with a number after it, starting at 1 and continuing upward.  The units of file_size are millions of bytes (1,000,000 bytes, not 1,048,576 bytes).

=> takze limit 5MB, max 10 suborov:

Kód: [Vybrat]
tcpdump <...> -C 5 -W 10 -w rec.pcap
Problem s pravami na interface: https://askubuntu.com/questions/530920/tcpdump-permissions-problem
Problem s pravom zapisu (sudo + '-C'): https://github.com/the-tcpdump-group/tcpdump/issues/448

Re:tcpdump
« Odpověď #2 kdy: 28. 07. 2015, 10:48:01 »
A v čem je problém? Man to popisuje naprosto jasně:

Kód: [Vybrat]
tcpdump ... [ -C file_size ] ... [ -w file ]

       -C     Before writing a raw packet to a savefile, check whether the file is currently larger than  file_size  and,  if
              so, close the current savefile and open a new one.  Savefiles after the first savefile will have the name spec-
              ified with the -w flag, with a number after it, starting at 1 and continuing upward.  The  units  of  file_size
              are millions of bytes (1,000,000 bytes, not 1,048,576 bytes).

       -w   Write the raw packets to file rather than parsing and printing them out.  They can later be printed with the -r
              option.  Standard output is used if file is ``-''.

Všimni si, že s "-w" se neukládá textový popis paketů, ale samotná data tak, jak jsou. To je úspornější. Další možnost úspory je vyfiltrovat jenom to, co tě zajímá.

ATomas

Re:tcpdump
« Odpověď #3 kdy: 28. 07. 2015, 11:02:38 »
Dobře děkuji, funguje to. Ovšem nešlo by nějk nastavit, aby to psalo vystup v té čitelné podobě (myslím ten klasický výstup, který jde číst v txt) ? O místo mi nejde místa na disku mám habaděj.

Re:tcpdump
« Odpověď #4 kdy: 28. 07. 2015, 11:05:51 »
Ovšem nešlo by nějk nastavit, aby to psalo vystup v té čitelné podobě (myslím ten klasický výstup, který jde číst v txt) ?
Ne. Ale když máš ty pcap soubory, tak si je můžeš do čitelné podoby převést tím příkazem, který jsi původně používal, akorát místo "-i eth0" tam dáš "-r my-pcap-file"


ATomas

Re:tcpdump
« Odpověď #5 kdy: 28. 07. 2015, 11:12:18 »
Skvele funguje to! Dekuju moc vsem za rady. Jste uzasni ! :)