Scapyの勉強
プロのサイトを読みながらコード書いてみた
pip3 install scapy-python3 でパケットに恋したい。 arpテーブルを汚したい編 - じゃあ、おうちで学べる
インストール
pip3 install scapy-python3
Macはついでにこれも
brew install libdnet
エラー起きた
koyama-mbp:Scapy-Practice tkoyama$ brew link intltool
Linking /usr/local/Cellar/intltool/0.51.0...
Error: Could not symlink share/man/man8/intltool-extract.8
/usr/local/share/man/man8 is not writable.
ひとまずドクター!
brew install nmap で発生したインストール時のエラーをchownで解決 - Qiita
brew doctor
解決策
Homebrew: Could not symlink, /usr/local/bin is not writable - Stack Overflow
sudo chown -R tkoyama:admin /usr/local/share/man/
またエラー
WARNING: Could not load module netifaces: No module named 'netifaces'
解決策
Python3でDashButtonのARPを見る | たくのこ Web
pip3 install netifaces
練習
>>> source='10.104.48.53'
>>> dest='10.104.52.82'
>>> eth=Ether(src=source, dst=dest)
>>> ip=IP(src=source, dst=dest)
>>> ip.ttl=5
>>> ip
<IP ttl=5 src=10.104.48.53 dst=10.104.52.82 |>
>>> eth
<Ether dst=10.104.52.82 src=10.104.48.53 |>
>>> ip
<IP ttl=5 src=10.104.48.53 dst=10.104.52.82 |>
>>> eth
<Ether dst=10.104.52.82 src=10.104.48.53 |>
>>> ip
<IP ttl=5 src=10.104.48.53 dst=10.104.52.82 |>
send(IP()/TCP())
sr1( IP()/ICMP())
>>> k[1]
<Ether dst=18:65:90:cd:c8:53 src=08:00:27:bd:1c:0c type=0x800 |<IP version=4 ihl=5 tos=0x0 len=60 id=0 flags=DF frag=0 ttl=63 proto=tcp chksum=0xba5e src=192.168.0.7 dst=192.168.0.6 options=[] |<TCP sport=http_alt dport=50632 seq=2138018704 ack=2118189087 dataofs=10 reserved=0 flags=SA window=28960 chksum=0x7299 urgptr=0 options=[('MSS', 1460), ('SAckOK', b''), ('Timestamp', (360772, 259709787)), ('NOP', None), ('WScale', 7)] |>>>
>>>
>>> k[0].psdump("/home/tkoyama/test_out.eps", layer_shift=1)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/scapy/packet.py", line 405, in psdump
canvas = self.canvas_dump(**kargs)
File "/usr/local/lib/python3.6/site-packages/scapy/packet.py", line 527, in canvas_dump
pt = pyx.text.text(XSTART, (YTXT-y)*YMUL, r"\font\cmssfont=cmss10\cmssfont{%s}" % proto.name, [ pyx.text.size.Large])
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1428, in wrapped
return f(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1464, in text
return self.instance.text(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1304, in text
return self.text_pt(unit.topt(x), unit.topt(y), *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1278, in text_pt
left_pt, right_pt, height_pt, depth_pt = self.do_typeset(expr, self.texmessages_run_default + self.texmessages_run + texmessages)
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1204, in do_typeset
return self._execute(expr, texmessages, STATE_TYPESET, STATE_TYPESET)
File "/usr/local/lib/python3.6/site-packages/pyx/text.py", line 1071, in _execute
self.texoutput.expect("PyXInputMarker:executeid=%i:" % self.executeid)
AttributeError: 'SingleTexRunner' object has no attribute 'texoutput'
>>>