hping 安装与使用

[root@7bbf9d785f-cx7tw /]# yum -y install libpcap-devel tcl-devel

Loaded plugins: fastestmirror, langpacks
ADDOPS-base                                                                                                                                                                                                                                                                                          | 2.9 kB  00:00:00     
base                                                                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
centosplus                                                                                                                                                                                                                                                                                           | 2.9 kB  00:00:00     
epel                                                                                                                                                                                                                                                                                                 | 2.9 kB  00:00:00     
extras                                                                                                                                                                                                                                                                                               | 2.9 kB  00:00:00     
updates                                                                                                                                                                                                                                                                                              | 2.9 kB  00:00:00     
(1/6): ADDOPS-base/7/x86_64/primary_db                                                                                                                                                                                                                                                               | 1.0 MB  00:00:00     
(2/6): extras/7/x86_64/primary_db                                                                                                                                                                                                                                                                    | 250 kB  00:00:00     
(3/6): base/7/x86_64/primary_db                                                                                                                                                                                                                                                                      | 6.1 MB  00:00:00     
(4/6): centosplus/7/x86_64/primary_db                                                                                                                                                                                                                                                                | 8.3 MB  00:00:00     
(5/6): epel/x86_64/primary_db                                                                                                                                                                                                                                                                        | 7.7 MB  00:00:00     
(6/6): updates/7/x86_64/primary_db                                                                                                                                                                                                                                                                   |  25 MB  00:00:00     
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package libpcap-devel.x86_64 14:1.5.3-13.el7_9 will be installed
--> Processing Dependency: libpcap = 14:1.5.3-13.el7_9 for package: 14:libpcap-devel-1.5.3-13.el7_9.x86_64
---> Package tcl-devel.x86_64 1:8.5.13-8.el7 will be installed
--> Processing Dependency: tcl = 1:8.5.13-8.el7 for package: 1:tcl-devel-8.5.13-8.el7.x86_64
--> Running transaction check
---> Package libpcap.x86_64 14:1.5.3-9.el7 will be updated
---> Package libpcap.x86_64 14:1.5.3-13.el7_9 will be an update
---> Package tcl.x86_64 1:8.5.13-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================================================================================================
 Package                                                                        Arch                                                                    Version                                                                              Repository                                                                Size
============================================================================================================================================================================================================================================================================================================================
Installing:
 libpcap-devel                                                                  x86_64                                                                  14:1.5.3-13.el7_9                                                                    updates                                                                  118 k
 tcl-devel                                                                      x86_64                                                                  1:8.5.13-8.el7                                                                       base                                                                     165 k
Installing for dependencies:
 tcl                                                                            x86_64                                                                  1:8.5.13-8.el7                                                                       base                                                                     1.9 M
Updating for dependencies:
 libpcap                                                                        x86_64                                                                  14:1.5.3-13.el7_9                                                                    updates                                                                  139 k

Transaction Summary
============================================================================================================================================================================================================================================================================================================================
Install  2 Packages (+1 Dependent package)
Upgrade             ( 1 Dependent package)

Total download size: 2.3 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/4): libpcap-1.5.3-13.el7_9.x86_64.rpm                                                                                                                                                                                                                                                             | 139 kB  00:00:00     
(2/4): libpcap-devel-1.5.3-13.el7_9.x86_64.rpm                                                                                                                                                                                                                                                       | 118 kB  00:00:00     
(3/4): tcl-devel-8.5.13-8.el7.x86_64.rpm                                                                                                                                                                                                                                                             | 165 kB  00:00:00     
(4/4): tcl-8.5.13-8.el7.x86_64.rpm                                                                                                                                                                                                                                                                   | 1.9 MB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                                                                                                       8.9 MB/s | 2.3 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:tcl-8.5.13-8.el7.x86_64                                                                                                                                                                                                                                                                                1/5 
  Updating   : 14:libpcap-1.5.3-13.el7_9.x86_64                                                                                                                                                                                                                                                                         2/5 
  Installing : 14:libpcap-devel-1.5.3-13.el7_9.x86_64                                                                                                                                                                                                                                                                   3/5 
  Installing : 1:tcl-devel-8.5.13-8.el7.x86_64                                                                                                                                                                                                                                                                          4/5 
  Cleanup    : 14:libpcap-1.5.3-9.el7.x86_64                                                                                                                                                                                                                                                                            5/5 
  Verifying  : 14:libpcap-1.5.3-13.el7_9.x86_64                                                                                                                                                                                                                                                                         1/5 
  Verifying  : 1:tcl-8.5.13-8.el7.x86_64                                                                                                                                                                                                                                                                                2/5 
  Verifying  : 1:tcl-devel-8.5.13-8.el7.x86_64                                                                                                                                                                                                                                                                          3/5 
  Verifying  : 14:libpcap-devel-1.5.3-13.el7_9.x86_64                                                                                                                                                                                                                                                                   4/5 
  Verifying  : 14:libpcap-1.5.3-9.el7.x86_64                                                                                                                                                                                                                                                                            5/5 

Installed:
  libpcap-devel.x86_64 14:1.5.3-13.el7_9                                                                                                                           tcl-devel.x86_64 1:8.5.13-8.el7                                                                                                                          

Dependency Installed:
  tcl.x86_64 1:8.5.13-8.el7                                                                                                                                                                                                                                                                                                 

Dependency Updated:
  libpcap.x86_64 14:1.5.3-13.el7_9                                                                                                                                                                                                                                                                                          

Complete!

[root@7bbf9d785f-cx7tw /]# yum -y groupinstall development tools 

Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Warning: group development does not exist.
Warning: group tools does not exist.
Maybe run: yum groups mark install (see man yum)
Error: No packages in any requested group available to install or update
[root@moss-test-mss-customer-api-x-7bbf9d785f-cx7tw /]#  ln -s /usr/include/pcap-bpf.h /usr/include/net/bpf.h
[root@moss-test-mss-customer-api-x-7bbf9d785f-cx7tw /]# git clone https://github.com/antirez/hping.git
Cloning into 'hping'...
remote: Enumerating objects: 225, done.
remote: Total 225 (delta 0), reused 0 (delta 0), pack-reused 225
Receiving objects: 100% (225/225), 811.36 KiB | 1017.00 KiB/s, done.
Resolving deltas: 100% (31/31), done.
[root@7bbf9d785f-cx7tw /]# ls
bin  boot  data  dev  etc  export  home  hping  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

[root@7bbf9d785f-cx7tw /]# cd hping/
[root@7bbf9d785f-cx7tw /hping]# ./configure 
build byteorder.c...
create byteorder.h...
./configure: line 81: -: command not found
--------------------------------------
system type: LINUX

LIBPCAP      : PCAP=-lpcap
PCAP_INCLUDE : 
MANPATH      : /usr/local/man
USE_TCL      : -DUSE_TCL
TCL_VER      : 
TCL_INC      : 
LIBTCL       : -ltcl -lm -lpthread
TCLSH        : 

(to modify try configure --help)
--------------------------------------
creating Makefile...
creating dependences...
now you can try `make'

[root@7bbf9d785f-cx7tw /hping]# make

gcc -c -O2 -Wall   -DUSE_TCL -g  main.c
gcc -c -O2 -Wall   -DUSE_TCL -g  getifname.c
getifname.c: In function ‘get_if_name’:
getifname.c:61:11: warning: ‘sa.sin_addr.s_addr’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     printf("DEBUG: Output interface address: %s\n",
           ^
gcc -c -O2 -Wall   -DUSE_TCL -g  getlhs.c
gcc -c -O2 -Wall   -DUSE_TCL -g  parseoptions.c
gcc -c -O2 -Wall   -DUSE_TCL -g  datafiller.c
gcc -c -O2 -Wall   -DUSE_TCL -g  datahandler.c
gcc -c -O2 -Wall   -DUSE_TCL -g  gethostname.c
gcc -c -O2 -Wall   -DUSE_TCL -g  binding.c
gcc -c -O2 -Wall   -DUSE_TCL -g  getusec.c
gcc -c -O2 -Wall   -DUSE_TCL -g  opensockraw.c
gcc -c -O2 -Wall   -DUSE_TCL -g  logicmp.c
gcc -c -O2 -Wall   -DUSE_TCL -g  waitpacket.c
gcc -c -O2 -Wall   -DUSE_TCL -g  resolve.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendip.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendicmp.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendudp.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendtcp.c
gcc -c -O2 -Wall   -DUSE_TCL -g  cksum.c
gcc -c -O2 -Wall   -DUSE_TCL -g  statistics.c
gcc -c -O2 -Wall   -DUSE_TCL -g  usage.c
gcc -c -O2 -Wall   -DUSE_TCL -g  version.c
gcc -c -O2 -Wall   -DUSE_TCL -g  antigetopt.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sockopt.c
gcc -c -O2 -Wall   -DUSE_TCL -g  listen.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendhcmp.c
gcc -c -O2 -Wall   -DUSE_TCL -g  memstr.c
gcc -c -O2 -Wall   -DUSE_TCL -g  rtt.c
gcc -c -O2 -Wall   -DUSE_TCL -g  relid.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendip_handler.c
gcc -c -O2 -Wall   -DUSE_TCL -g  libpcap_stuff.c
libpcap_stuff.c: In function ‘open_pcap’:
libpcap_stuff.c:26:6: warning: variable ‘on’ set but not used [-Wunused-but-set-variable]
  int on;
      ^
gcc -c -O2 -Wall   -DUSE_TCL -g  memlockall.c
gcc -c -O2 -Wall   -DUSE_TCL -g  memunlockall.c
gcc -c -O2 -Wall   -DUSE_TCL -g  memlock.c
gcc -c -O2 -Wall   -DUSE_TCL -g  memunlock.c
gcc -c -O2 -Wall   -DUSE_TCL -g  ip_opt_build.c
gcc -c -O2 -Wall   -DUSE_TCL -g  display_ipopt.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sendrawip.c
gcc -c -O2 -Wall   -DUSE_TCL -g  signal.c
gcc -c -O2 -Wall   -DUSE_TCL -g  send.c
gcc -c -O2 -Wall   -DUSE_TCL -g  strlcpy.c
gcc -c -O2 -Wall   -DUSE_TCL -g  arsglue.c
gcc -c -O2 -Wall   -DUSE_TCL -g  random.c
gcc -c -O2 -Wall   -DUSE_TCL -g  scan.c
gcc -c -O2 -Wall   -DUSE_TCL -g  hstring.c
gcc -c -O2 -Wall   -DUSE_TCL -g  script.c
script.c: In function ‘GetPacketDescription’:
script.c:265:21: warning: pointer targets in initialization differ in signedness [-Wpointer-sign]
  unsigned char *p = (char*)data;
                     ^
script.c: In function ‘HpingSetFieldCmd’:
script.c:603:24: warning: variable ‘value’ set but not used [-Wunused-but-set-variable]
  char *layer, *field, *value, *packet;
                        ^
gcc -c -O2 -Wall   -DUSE_TCL -g  interface.c
gcc -c -O2 -Wall   -DUSE_TCL -g  adbuf.c
gcc -c -O2 -Wall   -DUSE_TCL -g  hex.c
gcc -c -O2 -Wall   -DUSE_TCL -g  apdutils.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sbignum.c
gcc -c -O2 -Wall   -DUSE_TCL -g  sbignum-tables.c
gcc -c -O2 -Wall   -DUSE_TCL -g  ars.c
In file included from ars.c:15:0:
ars.c: In function ‘ars_multi_cksum’:
ars.c:485:46: warning: comparison with string literal results in unspecified behavior [-Waddress]
   assert("else reached in ars_multi_cksum()" == "");
                                              ^
ars.c: In function ‘ars_bsd_fix’:
ars.c:909:20: warning: variable ‘ip’ set but not used [-Wunused-but-set-variable]
  struct ars_iphdr *ip;
                    ^
gcc -c -O2 -Wall   -DUSE_TCL -g  apd.c
apd.c: In function ‘ars_d_set_data’:
apd.c:889:7: warning: variable ‘err’ set but not used [-Wunused-but-set-variable]
   int err, blen;
       ^
gcc -c -O2 -Wall   -DUSE_TCL -g  split.c
gcc -c -O2 -Wall   -DUSE_TCL -g  rapd.c
gcc -o hping3 -O2 -Wall   -DUSE_TCL -g main.o getifname.o getlhs.o parseoptions.o datafiller.o datahandler.o gethostname.o binding.o getusec.o opensockraw.o logicmp.o waitpacket.o resolve.o sendip.o sendicmp.o sendudp.o sendtcp.o cksum.o statistics.o usage.o version.o antigetopt.o sockopt.o listen.o sendhcmp.o memstr.o rtt.o relid.o sendip_handler.o libpcap_stuff.o memlockall.o memunlockall.o memlock.o memunlock.o ip_opt_build.o display_ipopt.o sendrawip.o signal.o send.o strlcpy.o arsglue.o random.o scan.o hstring.o script.o interface.o adbuf.o hex.o apdutils.o sbignum.o sbignum-tables.o ars.o apd.o split.o rapd.o -L/usr/local/lib -lpcap  -ltcl -lm -lpthread

./hping3 -v
hping version 3.0.0-alpha-1 ($Id: release.h,v 1.4 2004/04/09 23:38:56 antirez Exp $)
This binary is TCL scripting capable
use `make strip' to strip hping3 binary
use `make install' to install hping3
[root@7bbf9d785f-cx7tw /hping]# hping3 -v
hping version 3.0.0-alpha-1 ($Id: release.h,v 1.4 2004/04/09 23:38:56 antirez Exp $)
This binary is TCL scripting capable

[root@7bbf9d785f-cx7tw /hping]# hping --help

usage: hping host [options]
  -h  --help      show this help
  -v  --version   show version
  -c  --count     packet count
  -i  --interval  wait (uX for X microseconds, for example -i u1000)
      --fast      alias for -i u10000 (10 packets for second)
      --faster    alias for -i u1000 (100 packets for second)
      --flood      sent packets as fast as possible. Don't show replies.
  -n  --numeric   numeric output
  -q  --quiet     quiet
  -I  --interface interface name (otherwise default routing interface)
  -V  --verbose   verbose mode
  -D  --debug     debugging info
  -z  --bind      bind ctrl+z to ttl           (default to dst port)
  -Z  --unbind    unbind ctrl+z
      --beep      beep for every matching packet received
Mode
  default mode     TCP
  -0  --rawip      RAW IP mode
  -1  --icmp       ICMP mode
  -2  --udp        UDP mode
  -8  --scan       SCAN mode.
                   Example: hping --scan 1-30,70-90 -S www.target.host
  -9  --listen     listen mode
IP
  -a  --spoof      spoof source address
  --rand-dest      random destionation address mode. see the man.
  --rand-source    random source address mode. see the man.
  -t  --ttl        ttl (default 64)
  -N  --id         id (default random)
  -W  --winid      use win* id byte ordering
  -r  --rel        relativize id field          (to estimate host traffic)
  -f  --frag       split packets in more frag.  (may pass weak acl)
  -x  --morefrag   set more fragments flag
  -y  --dontfrag   set dont fragment flag
  -g  --fragoff    set the fragment offset
  -m  --mtu        set virtual mtu, implies --frag if packet size > mtu
  -o  --tos        type of service (default 0x00), try --tos help
  -G  --rroute     includes RECORD_ROUTE option and display the route buffer
  --lsrr           loose source routing and record route
  --ssrr           strict source routing and record route
  -H  --ipproto    set the IP protocol field, only in RAW IP mode
ICMP
  -C  --icmptype   icmp type (default echo request)
  -K  --icmpcode   icmp code (default 0)
      --force-icmp send all icmp types (default send only supported types)
      --icmp-gw    set gateway address for ICMP redirect (default 0.0.0.0)
      --icmp-ts    Alias for --icmp --icmptype 13 (ICMP timestamp)
      --icmp-addr  Alias for --icmp --icmptype 17 (ICMP address subnet mask)
      --icmp-help  display help for others icmp options
UDP/TCP
  -s  --baseport   base source port             (default random)
  -p  --destport   [+][+]<port> destination port(default 0) ctrl+z inc/dec
  -k  --keep       keep still source port
  -w  --win        winsize (default 64)
  -O  --tcpoff     set fake tcp data offset     (instead of tcphdrlen / 4)
  -Q  --seqnum     shows only tcp sequence number
  -b  --badcksum   (try to) send packets with a bad IP checksum
                   many systems will fix the IP checksum sending the packet
                   so you'll get bad UDP/TCP checksum instead.
  -M  --setseq     set TCP sequence number
  -L  --setack     set TCP ack
  -F  --fin        set FIN flag
  -S  --syn        set SYN flag
  -R  --rst        set RST flag
  -P  --push       set PUSH flag
  -A  --ack        set ACK flag
  -U  --urg        set URG flag
  -X  --xmas       set X unused flag (0x40)
  -Y  --ymas       set Y unused flag (0x80)
  --tcpexitcode    use last tcp->th_flags as exit code
  --tcp-timestamp  enable the TCP timestamp option to guess the HZ/uptime
Clock skew detection
  --clock-skew     enable clock skew detection. Try with -S against open port
  --clock-skew-win window of time (in seconds) for CS detection. Default 300
  --clock-skew-shift timestamp samples to use for error correction. Default 5
  --clock-skew-packets-per-sample # of packets to extract a sample. Default 10
Common
  -d  --data       data size                    (default is 0)
  -E  --file       data from file
  -e  --sign       add 'signature'
  -j  --dump       dump packets in hex
  -J  --print      dump printable characters
  -B  --safe       enable 'safe' protocol
  -u  --end        tell you when --file reached EOF and prevent rewind
  -T  --traceroute traceroute mode              (implies --bind and --ttl 1)
  --tr-stop        Exit when receive the first not ICMP in traceroute mode
  --tr-keep-ttl    Keep the source TTL fixed, useful to monitor just one hop
  --tr-no-rtt       Don't calculate/show RTT information in traceroute mode
ARS packet description (new, unstable)
  --apd-send       Send the packet described with APD (see docs/APD.txt)

部分常用参数

-c  数据包数量

-v 显示版本

-h 显示帮助

-i 发送数据包间隔的时间     uX则是X微秒,列:-i u2000

-q  安静模式

-z 绑定ctcl+z到ttl(默认为目的的端口)

-Z 取消绑定ctrl+z键

[root@7bbf9d785f-cx7tw /hping]# hping3 -I eth0 -S 100.222.200.200  -p 80
HPING 100.222.200.200 (eth0 100.222.200.200): S set, 40 headers + 0 data bytes

--- 100.222.200.200 hping statistic ---
30 packets tramitted, 0 packets received, 100% packet loss
round-trip min/avg/max = 0.0/0.0/0.0 ms