개요

간단히 설명하자면, 네트워크 패킷을 커스텀하게 만들어서 전송해볼 수 있는 CLI라는 뜻이다.
TL;DR
Homebrew
를 이용해서 간편하게 설치한다.brew install draftbrew/tap/hping
히스토리
문제의 인식
Homebrew
의 토론 탭에서 문제제기를 접하게 되었다.본래
hping3
는 Homebrew
의 공식 리포에서 Formula로 제공되었으나, 현재는 disabled 되어있다. 이러한 상태에서는 설치 명령을 통해서도 설치가 불가능하다. 사용자는 여전히 사용하고 싶어하는 사람들이 있으니 복구시켜달라고 요청했지만, 관리자는 유지보수의 어려움과 보안 이슈로 힘들다는 답변을 제공했다.문제의 해결
문제점들을 파악하고 하나씩 해결해보자.
소스를 구해야 한다.
brew info hping ==> hping: stable 3.20051105 (bottled) Command-line oriented TCP/IP packet assembler/analyzer http://www.hping.org/ Disabled because it is not maintained upstream! It was disabled on 2024-02-15. Not installed From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/h/hping.rb ==> Analytics install: 18 (30 days), 32 (90 days), 1,461 (365 days) install-on-request: 18 (30 days), 32 (90 days), 1,461 (365 days) build-error: 3 (30 days)
오래 전에 disabled 처리가 되었는데, 주된 이유는 upstream이 관리되지 않기 때문이라고 한다. 실제로 http://www.hping.org 홈페이지는 접근이 되지 않으며, 마찬가지로 소스도 내려받을 수가 없었다. 다행히도 원 개발자가 소스를 Github에 공개해놨다.
hping
antirez • Updated Feb 21, 2025
소스를 빌드해야 한다.
기존에 제공되던
Homebrew
의 Formula에서 소스 경로만 바꿔서 빌드해보면 정상적으로 빌드가 진행되지 않는다. 복잡한 설정을 모두 삭제하고 본연의 설치 과정에 집중해본다. macOS에서 변경된 이름으로 헤더 이름 바꾸고, configure
를 --no-tcl
옵션으로 진행하며 make install
을 진행하고 있다.... def install # The net directory has been renamed to pcap in libpcap. # Submitted upstream in https://github.com/antirez/hping/pull/13. inreplace "libpcap_stuff.c", "net/bpf.h", "pcap/bpf.h" unless OS.mac? # Compile fails with tcl support; TCL on macOS is 32-bit only system "./configure", "--no-tcl" # Target folders need to exist before installing sbin.mkpath man8.mkpath system "make", "CC=#{ENV.cc}", "COMPILE_TIME=-D__LITTLE_ENDIAN__", "INSTALL_PATH=#{prefix}", "INSTALL_MANPATH=#{man}", "install" end
하나씩 살펴본다. 가장 먼저,
libpcap
헤더에 대한 처리는 이미 깃허브에서 소스 변경처리가 되어있는 것을 확인할 수 있었다. 그래서 설치 과정에서의 소스 변경을 삭제하고 이미 macOS에 설치된 것을 가져다 쓸 수 있도록 명령을 추가하였다.... uses_from_macos "libpcap" def install # Compile fails with tcl support; TCL on macOS is 32-bit only system "./configure", "--no-tcl" ... end
이제 설치를 진행해본다. 첫 번째 오류는
install
과정에서 발생했다. Makefile
을 살펴보니 시스템 경로에 바이너리 파일을 곧바로 설치하려고 시도하고 있었다. ... install: hping3 cp -f hping3 /usr/sbin/ chmod 755 /usr/sbin/hping3 ln -s /usr/sbin/hping3 /usr/sbin/hping ln -s /usr/sbin/hping3 /usr/sbin/hping2 @if [ -d ${INSTALL_MANPATH}/man8 ]; then \ cp ./docs/hping3.8 ${INSTALL_MANPATH}/man8; \ chmod 644 ${INSTALL_MANPATH}/man8/hping3.8; \ else \ echo "@@@@@@ WARNING @@@@@@"; \ echo "Can't install the man page: ${INSTALL_MANPATH}/man8 does not exist"; \ fi ...
macOS 최신 버전에서는
/usr
하위 경로를 직접 편집할 수 없기 때문에 Homebrew
에서도 /opt
하위에 별도의 경로를 만들어 PATH에 등록하고 바이너리를 제공하고 있다. 그렇기 때문에 install
명령을 사용하지 않고 설치 과정을 현대의 방식에 맞도록 직접 구현하자.... uses_from_macos "libpcap" def install # Compile fails with tcl support; TCL on macOS is 32-bit only system "./configure", "--no-tcl" system "make", "CC=#{ENV.cc}", "COMPILE_TIME=-D__LITTLE_ENDIAN__" bin.install "hping3" bin.install_symlink "hping3" => "hping" bin.install_symlink "hping3" => "hping2" man8.install "docs/hping3.8" end
설치 오류는 해결되었다. 대신에
tcl
기능이 빠지면서 제대로 동작하는 기능이 많지 않다. 이를 추가하기 위해서 옵션을 제거하고 빌드를 진행했는데, 관련 기능을 찾지 못해서 또 오류가 난다. 골치아프지만 검색을 해봤는데, 소스가 공개된 깃허브 리포의 이슈에서 다른 사람들이 이미 처리한 내용을 찾아볼 수 있었다.Sorry, this hping binary was compiled without TCL scripting support :(
간단하게 요약해보자면,
tcl-tk
를 설치하고 configure
도중에 해당 라이브러리를 찾을 수 있도록 설정을 수정하라는 것이었다. 소스 리포는 업데이트가 거의 이루어지지 않기 때문에 코드를 수정하는 패치를 설치 과정에 진행할 수 있도록 코드를 추가하였다.... depends_on "tcl-tk" uses_from_macos "libpcap" patch :DATA def install system "./configure" system "make", "CC=#{ENV.cc}", "COMPILE_TIME=-D__LITTLE_ENDIAN__" bin.install "hping3" bin.install_symlink "hping3" => "hping" bin.install_symlink "hping3" => "hping2" man8.install "docs/hping3.8" end __END__ diff --git a/configure b/configure index dab04ab..d1e7d1d 100755 --- a/configure +++ b/configure @@ -61,9 +61,9 @@ esac # # TCL detection # -for TCLPATH_TRY in "/usr/bin/" "/usr/local/bin/" "/bin/" +for TCLPATH_TRY in "/usr/bin/" "/usr/local/bin/" "/bin/" "/opt/homebrew/opt/tcl-tk/bin/" do - for TCLVER_TRY in "8.4" "8.3" "8.2" "8.1" "8.0" + for TCLVER_TRY in "8.4" "8.3" "8.2" "8.1" "8.0" "8.6" do if [ -z $TCLSH ] then @@ -81,7 +81,10 @@ then TCL_VER=`echo puts \\$tcl_version | $TCLSH -` USE_TCL='-DUSE_TCL' TCL_LIB="-ltcl${TCL_VER}" - if [ -e /usr/include/tcl${TCL_VER} ] + if [ -e /opt/homebrew/opt/tcl-tk/lib/tcl${TCL_VER} ] + then + TCL_INC="-I/opt/homebrew/opt/tcl-tk/lib${TCL_VER}" + elif [ -e /usr/include/tcl${TCL_VER} ] then TCL_INC="-I/usr/include/tcl${TCL_VER}" elif [ -e /usr/include/tcl.h ]
configure
파일에서는 시스템의 특정 경로에서만 TCL을 찾고 있다. 의존성으로 설치한 라이브러리를 찾을 수 있도록 Homebrew
내의 설치 경로와 버전을 추가함으로써 TCL을 찾고, 이를 이용해서 정상적으로 빌드할 수 있도록 했다. 이로써 오류는 모두 해결되었다.바이너리를 배포해야 한다.
바이너리를 배포하기 위해서는
Homebrew
에 Formula를 등록하면 편하겠지만, 앞서 관리자가 지적한 부분들은 해결이 되지 않았기 때문에 커스텀 리포를 사용해야 한다. 운이 좋게도 본인이 직접 구축해서 관리하고 있던 draftbrew/tap
리포를 이용하여 Formula를 배포할 수 있다.hping.rb
DraftBrew
설치하기
커스텀 리포에서 배포되는 패키지 설치를 위해서는 패키지 이름 앞에 리포 이름을 추가해서 설치해주면 된다.
brew install draftbrew/tap/hping ==> Fetching dependencies for draftbrew/tap/hping: tcl-tk ==> Fetching tcl-tk ==> Downloading https://ghcr.io/v2/homebrew/core/tcl-tk/manifests/8.6.14 Already downloaded: /Users/daeho.ro/Library/Caches/Homebrew/downloads/0e0bf7bf267ffebaf93f7073e662653e2e6b892f68642d8ca120d6134d2c5eb9--tcl-tk-8.6.14.bottle_manifest.json ==> Downloading https://ghcr.io/v2/homebrew/core/tcl-tk/blobs/sha256:fd7e83ade328ee3637f37f7 Already downloaded: /Users/daeho.ro/Library/Caches/Homebrew/downloads/dcf720b7901fd3d345c80d37799d776c2f7928f2f0fb5b0b2b0ee24fcfc64b7f--tcl-tk--8.6.14.arm64_sonoma.bottle.tar.gz ==> Fetching draftbrew/tap/hping ==> Cloning https://github.com/antirez/hping.git Updating /Users/daeho.ro/Library/Caches/Homebrew/hping--git ==> Checking out branch master Already on 'master' Your branch is up to date with 'origin/master'. HEAD is now at 3547c76 .gitignore file added. ==> Installing hping from draftbrew/tap ==> Installing dependencies for draftbrew/tap/hping: tcl-tk ==> Installing draftbrew/tap/hping dependency: tcl-tk ==> Downloading https://ghcr.io/v2/homebrew/core/tcl-tk/manifests/8.6.14 Already downloaded: /Users/daeho.ro/Library/Caches/Homebrew/downloads/0e0bf7bf267ffebaf93f7073e662653e2e6b892f68642d8ca120d6134d2c5eb9--tcl-tk-8.6.14.bottle_manifest.json ==> Verifying attestation for tcl-tk ==> Pouring tcl-tk--8.6.14.arm64_sonoma.bottle.tar.gz 🍺 /opt/homebrew/Cellar/tcl-tk/8.6.14: 3,065 files, 53.2MB ==> Installing draftbrew/tap/hping ==> Patching ==> ./configure ==> make CC=clang COMPILE_TIME=-D__LITTLE_ENDIAN__ 🍺 /opt/homebrew/Cellar/hping/3.0.0-alpha-1: 13 files, 228.7KB, built in 8 seconds ==> Running `brew cleanup hping`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
사용하기
sudo hping -1 172.30.1.254 -c 3 -d 10 HPING 172.30.1.254 (en0 172.30.1.254): icmp mode set, 28 headers + 10 data bytes len=38 ip=172.30.1.254 ttl=64 id=44953 icmp_seq=0 rtt=2.3 ms len=38 ip=172.30.1.254 ttl=64 id=45034 icmp_seq=1 rtt=1.9 ms len=38 ip=172.30.1.254 ttl=64 id=45048 icmp_seq=2 rtt=5.9 ms --- 172.30.1.254 hping statistic --- 3 packets tramitted, 3 packets received, 0% packet loss round-trip min/avg/max = 1.9/3.4/5.9 ms
잘 동작한다.