äžçŽ
Atheris ã䜿çšãã LibFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ãã¶
ãã¹ã察象㯠Python ã¿ãŒã²ããã§ãã? ãã®ã¬ãã¹ã³ã§ã¯ãAtheris ã¢ãžã¥ãŒã«ã䜿çšãã LibFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ããããã¹ãããæ¹æ³ãé ãè¿œã£ãŠèª¬æããŸãã
åŠç¿æéã®ç®å®: 15 å
ãã®ã¬ãã¹ã³ãçµäºãããšã以äžã®ããšãã§ããããã«ãªããŸãã
- ãã£ãããããªãäŸå€ã®æ¬ é¥ããã Atheris ã¢ãžã¥ãŒã«ã䜿çšãã libFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ãããã³ã³ãã€ã«ãããã¡ãžã³ã°ããã
- ã€ã³ããã¯ã¹å¢çå€ã®æ¬ é¥ããã Atheris ã¢ãžã¥ãŒã«ã䜿çšãã libFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ãããã³ã³ãã€ã«ãããã¡ãžã³ã°ããã
ã¬ãã¹ã³ãé§ã足ã§
å§ããåã«åææ¡ä»¶ã確èªããŸãã
-
python-atheris.tgz ãããŠã³ããŒããã
python-atheris
Docker ã€ã¡ãŒãžããã«ãããæå®ããã Docker ã¬ãžã¹ããªã«ããã·ã¥ããŸããdocker build -f Dockerfile -t <DOCKERHUB_USERNAME>/python-atheris . docker push <DOCKERHUB_USERNAME>/python-atheris
docker build -f Dockerfile -t $MAYHEM_DOCKER_REGISTRY/forallsecure/python-atheris . docker push $MAYHEM_DOCKER_REGISTRY/forallsecure/python-atheris
-
Mayhem UI ãŸã㯠Mayhem CLI ã§æ¬¡ã® Mayhemfile ã䜿çšããŠ
forallsecure/python-atheris
Docker ã€ã¡ãŒãžã«å¯Ÿã㊠Mayhem ã©ã³ãå®è¡ããŸãã1 2 3 4 5 6 7
image: <DOCKERHUB_USERNAME>/python-atheris:latest duration: 90 project: mayhem-examples target: python-atheris cmds: - cmd: /mayhemit.py libfuzzer: true
1 2 3 4 5 6 7
image: $MAYHEM_DOCKER_REGISTRY/forallsecure/python-atheris:latest duration: 90 project: python target: python-atheris cmds: - cmd: /mayhemit.py libfuzzer: true
以äžãå¿ èŠã§ãã
- Docker ãã€ã³ã¹ããŒã«ãããŠããããš
- æå¹ãªã€ã³ã¿ãŒãããæ¥ç¶ (Docker Hub ããŒã¹ ã€ã¡ãŒãžããã«ãããã)
ã¯ã³ ã¯ãªã㯠ãã¹ã¶
äžã®ãã¿ã³ãã¯ãªãã¯ã㊠Python ã¿ãŒã²ããã®ãã¹ããéå§ããŸããæçµç¢ºèªããŒãžã«å°éãããŸã§ [Next] ãã¯ãªãã¯ãã[Start Run] ãã¯ãªãã¯ããŸãã
次ã®ãããªã©ã³ ããŒãžã衚瀺ãããŸãã
Mayhem ã«ãã Python ã¿ãŒã²ããã®ãã¹ãã確èªããã®ã§ã次ã«ãã©ã®ããã« Python ã¿ãŒã²ããããã«ããããã®ããé ãè¿œã£ãŠèª¬æããŸãã
Mayhem ã§ã® Atheris ã䜿çšãã Python ã¿ãŒã²ããã®ãã¹ã¶
ãã¡ã€ã«: python-atheris.tgz
äžèšã® python-atheris.tgz
ãããŠã³ããŒãããŠå±éãã次ã®è匱æ§ã®ãã mayhemit.py
ããã°ã©ã ãèŠãŠã¿ãŸãããã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Info
Python ã§ã€ã³ããã¯ã¹ã䜿çšã㊠bytestring ã«ã¢ã¯ã»ã¹ãããšãæŽæ°ãè¿ãããŸãããã®ãããstring æåã®ãŠãã³ãŒã ã³ãŒã ãã€ã³ããè¡šçŸããæŽæ°ãè¿ã ord()
ã䜿çšãããŠããŸããdata[0] == ord('b')
ã true ã«è©äŸ¡ãããçã®æ¡ä»¶ã䜿çšããŠããã®ã¯ãã®ããã§ãã
Warning
atheris ããŒãã¹ ã¹ã¯ãªããã«è€æ°ã®ã¿ãŒã²ãã (ããšãã° foo
ããã³ bar
) ãå«ãŸããŠãããã³ãã³ã ã©ã€ã³åŒæ° (äŸ: foo
) ã«ãã£ãŠã©ããéžæããããå¶åŸ¡ããŠããå Žåãatheris.Setup
ã®åŒã³åºããå®è¡ããåã«ã(sys.argv.pop(1)
ãªã©ã䜿çšããŠ) sys.argv
ãã該åœåŒæ°ãé€å€ããå¿
èŠããããŸããããã§ãªããã°ãatheris ã¯äœå㪠(æªç¥ã®) åŒæ°ããã¹ã ã¿ãŒã²ããã«æž¡ããŸããäœåãªåŒæ°ãåé€ãããªãå Žåã Mayhem ã©ã³ã¯äœåãªåŒæ°ã«ãã "unexpected libFuzzer argument" ãšã©ãŒã§å€±æããŸãã
atheris
ããã³ sys
ã¢ãžã¥ãŒã«ãããã°ã©ã ã«ã€ã³ããŒããããé¢æ° TestOneInput
ãå
¥åãã©ã¡ãŒã¿ãŒ data
ãåãåãããšãããããŸãããã®å
¥åãã©ã¡ãŒã¿ãŒããã§ãã¯ã㊠"bug" ãšããã€ã¥ããã©ããããã§ãã¯ããŠããŸãã"bug" ã§ããå Žåãè¡ 12ã§ãã£ãããããªãäŸå€ã®æ¬ é¥ã«ãã£ãŠããã°ã©ã ãã¯ã©ãã·ã¥ããŸãã
è¡ 12 ããã³ 13ã§ãatheris
ã¢ãžã¥ãŒã«ã¯ Setup
ããã³ Fuzz
é¢æ°ã䜿çšããŠãã¹ã ãšã³ããªãã€ã³ããã»ããã¢ããããŠããŸãã
次ã«ãé¢é£ãã Dockerfile
ãèŠãŠãpython-atheris
ãã©ã®ããã«ãã«ãããããã確èªããŸãããã
1 2 3 4 5 6 |
|
- è¡ 1: ãã«ã ã¹ããŒãž Docker ã³ã³ãããŒå
ã«å¿
èŠãª
atheris
äŸåé¢ä¿ãçšæãããããããŒã¹ç°å¢ãšããŠfuzzers/atheris:2.0.7-python3.9
ããŒã¹ ã€ã¡ãŒãžãèšå®ãããŠããŸãã - è¡ 2:
fuzzers/atheris:2.0.7-python3.9
Docker ã³ã³ãããŒã«mayhemit.py
ãœãŒã¹ ãã¡ã€ã«ãã³ããŒãããŠããŸãã - è¡ 3: ãã«ãããã Docker ã€ã¡ãŒãžã®ããã©ã«ãå®è¡ãã¡ã€ã«ãšããŠ
/mayhemit.py
å®è¡ãã¡ã€ã«ãèšå®ãããŠããŸãã
Note
python-atheris
ã¿ãŒã²ããã«å¿
èŠãªã³ã³ãã€ã« ã¹ãããããªãããšã«æ°ã¥ããããããŸãããã³ã³ãã€ã«ãå¿
èŠãªä»ã®èšèªã®ã¿ãŒã²ãããšç°ãªããPython ã¯ã€ã³ã¿ãŒããªã¿ãŒèšèªã§ãããããã³ã³ãã€ã«ã¯å¿
èŠãããŸããã
次ã«ãdocker build
ããã³ docker push
ã³ãã³ãã䜿çšããŠãDocker ã€ã¡ãŒãžããã«ãã㊠Docker Hub ã¬ãžã¹ããªã«ããã·ã¥ããå¿
èŠããããŸããpython-atheris
ãã©ã«ããŒå
ã«ããããšã確èªãã次ã®ã³ãã³ããå®è¡ããŸãã
次ã«ãdocker build
ããã³ docker push
ã³ãã³ãã䜿çšããŠãDocker ã€ã¡ãŒãžããã«ãã㊠Mayhem ãµãŒããŒã«ããã·ã¥ããå¿
èŠããããŸãã$MAYHEM_DOCKER_REGISTRY
ã¯ããã©ã€ããŒã㪠Mayhem Docker ã¬ãžã¹ããªã® URL ãè¡šãç°å¢å€æ°ã§ããpython-atheris
ãã©ã«ããŒå
ã«ããããšã確èªãã次ã®ã³ãã³ããå®è¡ããŸãã
docker build -f Dockerfile -t <DOCKERHUB_USERNAME>/python-atheris .
docker push <DOCKERHUB_USERNAME>/python-atheris
docker build -f Dockerfile -t $MAYHEM_DOCKER_REGISTRY/forallsecure/python-atheris .
docker push $MAYHEM_DOCKER_REGISTRY/forallsecure/python-atheris
Info
mayhem login
ã³ãã³ãã䜿çšããŠå
éšç㪠Mayhem Docker ã¬ãžã¹ããªã® URL ãæ€çŽ¢ãã次ã®ã³ãã³ãã䜿çšã㊠DOCKER_REGISTRY
ç°å¢å€æ°ãèšå®ã§ããŸã:
export DOCKER_REGISTRY=tutorial.forallsecure.com:5000
DOCKER_REGISTRY
ç°å¢å€æ°ã«èªèº«ã® Mayhem Docker ã¬ãžã¹ã㪠URL ãèšå®ããå¿
èŠããããŸãã
æ°ããäœæãã Docker ã€ã¡ãŒãžã Docker Hub ã¬ãžã¹ããªã«æ£åžžã«ããã·ã¥ããããMayhem UI ããæ°èŠã©ã³ãäœæãã<DOCKERHUB_USERNAME>/python-atheris
Docker ã€ã¡ãŒãžãæ€çŽ¢ããŸããMayhemfile
ã次ã®ããã«ãªã£ãŠããããšã確èªããŸãã
æ°ããäœæãã Docker ã€ã¡ãŒãžããã©ã€ããŒã㪠Mayhem Docker ã¬ãžã¹ããªã«æ£åžžã«ããã·ã¥ããããMayhem UI ããæ°èŠã©ã³ãäœæããforallsecure/python-atheris
Docker ã€ã¡ãŒãžãæ€çŽ¢ããŸããMayhemfile
ã次ã®ããã«ãªã£ãŠããããšã確èªããŸãã
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
æ°èŠã©ã³äœæãããŒã®æçµç¢ºèªããŒãžã«å°éãããŸã§ [Next] ãã¯ãªãã¯ãã[Start Run] ãã¯ãªãã¯ã㊠Mayhem ã©ã³ãå®è¡ããŸãã次ã®ãããªã©ã³ ããŒãžã衚瀺ãããŸãã
ããã§ãšãããããŸã! atheris
ãã¡ã¶ãŒ ã¢ãžã¥ãŒã«ã䜿çšãã Python ã¿ãŒã²ããã®ãã¹ããæåããŸããã
â¡ çŸå®çãªæŒç¿: Atheris ã䜿çšãã mayhemit-out-of-bounds
Python ã¿ãŒã²ããã®ãã«ããšãã¹ã¶
ãã£ãããããªãäŸå€ã®æ¬ é¥ããã Python ã¿ãŒã²ããã®ãã«ãããã³ãã¹ãæ¹æ³ãããã£ããšããã§ããœãŒã¹ ã³ãŒããä¿®æ£ããŠã€ã³ããã¯ã¹å¢çå€ã®æ¬ é¥ãæ€åºã§ãããã©ãããã£ãŠã¿ãŸãããã
ãã¡ã€ã«: mayhemit-out-of-bounds-unsolved.zip
æé
mayhemit.py
ãœãŒã¹ ã³ãŒããå€æŽãã次ã®è¡ãè¿œå ããŠé åå¢çå€æ¬ é¥ãèšå®ããŸãã
1 2 3 4 5 6 7 |
|
docker build
ã³ãã³ãã䜿çšããŠDockerfile
ãåãã«ãããçµæã® Docker ã€ã¡ãŒãžã<DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
ãšããŠã¿ã°ä»ãããŸããdocker push
ã³ãã³ãã䜿çšããŠãããªãã¯ãª Docker Hub ã¬ãžã¹ããªã«<DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžãããã·ã¥ããŸãã- Mayhem UI ãŸã㯠Mayhem CLI ã䜿çšããŠ
<DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžããã¡ãžã³ã°ããŸããMayhemfile
ãé©åã«èšå®ãããŠããããšã確èªããŸãã
docker build
ã³ãã³ãã䜿çšããŠDockerfile
ãåãã«ãããçµæã® Docker ã€ã¡ãŒãžã$MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
ãšããŠã¿ã°ä»ãããŸããdocker push
ã³ãã³ãã䜿çšããŠãã©ã€ããŒã㪠Mayhem Docker ã¬ãžã¹ããªã«$MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžãããã·ã¥ããŸãã- Mayhem UI ãŸã㯠Mayhem CLI ã䜿çšããŠ
$MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžããã¹ãããŸããMayhemfile
ãé©åã«èšå®ãããŠããããšã確èªããŸãã
ð 確èªAtheris ã䜿çšãã mayhemit-out-of-bounds
Python ã¿ãŒã²ããã®ãã«ããšãã¹ã¶
解ç
æš¡ç¯è§£ç: mayhemit-out-of-bounds-solved.zip
ãŸããTestOneInput
é¢æ°ããã¡ãžã³ã°ãããšããå
¥åãã¹ã ã±ãŒã¹ "bug" ãã€ã³ããã¯ã¹å¢çå€ãšã©ãŒãçºçããããããæ倧é·ã®å¶çŽ len(data) < 5
ããã³èª€ã£ãåŒã³åºã data[10]
ãè¿œå ããŸãã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
次ã«ãDockerfile
ãšåããã£ã¬ã¯ããªã§ docker build
ã³ãã³ããå®è¡ããçµæã® Docker ã€ã¡ãŒãžã« <DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
ãšããã¿ã°ãä»ããŸãã
次ã«ãDockerfile
ãšåããã£ã¬ã¯ããªã§ docker build
ã³ãã³ããå®è¡ããçµæã® Docker ã€ã¡ãŒãžã« $MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
ãšããã¿ã°ãä»ããŸãã
docker build -f Dockerfile -t <DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds .
docker build -f Dockerfile -t $MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds .
次ã«ã<DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžã«ã¿ã°ãä»ããŠãããªãã¯ãª Docker Hub ã¬ãžã¹ããªã«ããã·ã¥ããŸãã
次ã«ã$MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžã«ã¿ã°ãä»ããŠãã©ã€ããŒã㪠Mayhem Docker ã¬ãžã¹ããªã«ããã·ã¥ããŸãã
docker push <DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
docker push $MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
å¥ã®æ¹æ³ãšããŠãä»å±ã® Makefil ã䜿çšãã
MAYHEM_DOCKER_REGISTRY` ç°å¢å€æ°ãèšå®ããŠæ¬¡ã®ã³ãã³ããå®è¡ããããšã§ãç°¡åã«çµæã® Docker ã€ã¡ãŒãžããã«ãããããã·ã¥ããããšãã§ããŸãã
make build
make push
æåŸã«ãMayhem UI ãŸã㯠Mayhem CLI ã䜿çšããŠãã¢ããããŒãããã <DOCKERHUB_USERNAME>/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžã«å¯Ÿã㊠Mayhem ã©ã³ãå®è¡ããŸããMayhemfile
ã¯æ¬¡ã®ããã«ãªã£ãŠããã¯ãã§ãã
æåŸã«ãMayhem UI ãŸã㯠Mayhem CLI ã䜿çšããŠãã¢ããããŒãããã $MAYHEM_DOCKER_REGISTRY/python-atheris-mayhemit-out-of-bounds
Docker ã€ã¡ãŒãžã«å¯Ÿã㊠Mayhem ã©ã³ãå®è¡ããŸããMayhemfile
ã¯æ¬¡ã®ããã«ãªã£ãŠããã¯ãã§ãã
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
æçµçãªã©ã³ ããŒãžã¯æ¬¡ã®ããã«è¡šç€ºãããã¯ãã§ãã
ããã§ãšãããããŸã! Mayhem ãã€ã³ããã¯ã¹å¢çå€ã®æ¬ é¥ãçºèŠããŸãããã¹ã¯ã©ãããã Python ã¿ãŒã²ããããã«ãããAtheris ãã¡ã¶ãŒ ã¢ãžã¥ãŒã«ã䜿çšããŠãã°ãæ€åºã§ããŸããã
âïž ãŸãšããšæ¯ãè¿ã¶
ãã®ã¬ãã¹ã³ã§ã¯ãAtheris ãã¡ã¶ãŒ ã¢ãžã¥ãŒã«ããã³ Mayhem ã䜿çšã㊠libFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ããããã¡ãžã³ã°ããæ¹æ³ãåŠã³ãŸããã
åŠç¿å 容
1. Atheris ã䜿çšãã LibFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ããããã«ãããã³ãã¹ãããŠãã£ãããããªãäŸå€ã®æ¬ é¥ãæ€åºããã
-
ãœãŒã¹ ã³ãŒãã«ã¯æ¬¡ã®æ¬ é¥ãå«ãŸããŠããã¯ãã§ã:
1 2 3 4 5 6
def TestOneInput(data): if len(data) >= 3: if data[0] == ord('b'): if data[1] == ord('u'): if data[2] == ord('g'): raise Exception("Made it to the bug!")
-
Atheris ã䜿çšã㊠Python ã¿ãŒã²ããããã¡ãžã³ã°ããã«ã¯ã次㮠Dockerfile ã䜿çšã㊠Python ããã°ã©ã ãå«ã Docker ã€ã¡ãŒãžããã«ãããŸãã
1 2 3 4 5 6
FROM fuzzers/atheris:2.0.7-python3.9 COPY mayhemit.py /mayhemit.py # Set to fuzz! ENTRYPOINT [] CMD ["/mayhemit.py"]
2. Atheris ã䜿çšãã LibFuzzer ã€ã³ã¹ãã¥ã«ã¡ã³ããŒã·ã§ã³ä»ã Python ã¿ãŒã²ããããã«ãããã³ãã¡ãžã³ã°ããŠã€ã³ããã¯ã¹å¢çå€ã®æ¬ é¥ãæ€åºããã
-
ãœãŒã¹ ã³ãŒãã«ã¯æ¬¡ã®æ¬ é¥ãå«ãŸããŠããã¯ãã§ã:
1 2 3 4 5 6 7
def TestOneInput(data): if len(data) >= 3 and len(data) < 5: if data[0] == ord('b'): if data[1] == ord('u'): if data[2] == ord('g'): print("Made it to the bug!") return data[10]
-
Atheris ã䜿çšã㊠Python ã¿ãŒã²ããããã¡ãžã³ã°ããã«ã¯ã次㮠Dockerfile ã䜿çšã㊠Python ããã°ã©ã ãå«ã Docker ã€ã¡ãŒãžããã«ãããŸãã
1 2 3 4 5 6
FROM fuzzers/atheris:2.0.7-python3.9 COPY mayhemit.py /mayhemit.py # Set to fuzz! ENTRYPOINT [] CMD /mayhemit.py