Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20140904_(cyber_security)_How_to_automate_webha...
Search
re4lfl0w
September 22, 2015
Programming
0
17
20140904_(cyber_security)_How_to_automate_webhacking.kr_with_Python_presentation
20140904_(cyber_security)_How_to_automate_webhacking.kr_with_Python_presentation
re4lfl0w
September 22, 2015
Tweet
Share
Other Decks in Programming
See All in Programming
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
730
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
200
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
410
24時間止められないシステムを守る-医療ITにおけるランサムウェア対策の実際
koukimiura
1
110
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
180
CSC307 Lecture 05
javiergs
PRO
0
500
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
[SF Ruby Conf 2025] Rails X
palkan
1
760
A Soul's Torment
seathinner
5
2.3k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
Being A Developer After 40
akosma
91
590k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
AI: The stuff that nobody shows you
jnunemaker
PRO
2
270
RailsConf 2023
tenderlove
30
1.3k
Tell your own story through comics
letsgokoyo
1
810
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
54
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Transcript
How to automate webhacking.kr with python How to automate webhacking.kr
with Python © ઑӔ 2015 1
Who are you? • ઑӔ, թࢎۈ • Python જইೣ •
Data Analysis, TDD, Penetration Testing, DevOps, Machine Learning, NLP ҙब • githubgithub • ਵܻॆ euripy euripy http://euripy.github.io github https://github.com/re4lfl0w/ How to automate webhacking.kr with Python © ઑӔ 2015 2
Casting • ܻ࠭1 1 Hardware Hacking Training Epilogue How to
automate webhacking.kr with Python © ઑӔ 2015 3
Why? How to automate webhacking.kr with Python © ઑӔ 2015
4
... How to automate webhacking.kr with Python © ઑӔ 2015
5
5000 ѐ... How to automate webhacking.kr with Python © ઑӔ
2015 6
ੌ߈ੋ ಽח ցޖ ݆!! જই? Ӓۧݶ ର߹ചܳ ೞӝ ਤ೧ࢲח?? How
to automate webhacking.kr with Python © ઑӔ 2015 7
Python How to automate webhacking.kr with Python © ઑӔ 2015
8
Python How to automate webhacking.kr with Python © ઑӔ 2015
9
Python How to automate webhacking.kr with Python © ઑӔ 2015
10
Python!! How to automate webhacking.kr with Python © ઑӔ 2015
11
જই... Webhacking.kr ࢎր ೞ۞ оࠁ ੌױ ݾରܳ ೠ ߣ ࠊࠅө
How to automate webhacking.kr with Python © ઑӔ 2015 12
1ੌର • ۿ ߂ पण ળ࠺ • դب ೞ ޙઁ
ಽ(߄झ݀, ۄఠ ߸ઑ) How to automate webhacking.kr with Python © ઑӔ 2015 13
2ੌର • դب ޙઁ ಽ(ۄఠ ߸ઑ, XSS ١) How
to automate webhacking.kr with Python © ઑӔ 2015 14
3ੌର • դب ~ ࢚ ޙઁ ಽ(SQL Injection) How
to automate webhacking.kr with Python © ઑӔ 2015 15
߄झ݀ ۄఠ ߸ઑ XSS SQL Injection How to automate webhacking.kr
with Python © ઑӔ 2015 16
଼ਵ۽ח ݆ ࠌחؘ ޙઁ ಽח ݆ ೧ࠁ ঋ જই! ب
How to automate webhacking.kr with Python © ઑӔ 2015 17
Key Point How to automate webhacking.kr with Python © ઑӔ
2015 18
Key Point • ղо ݈ೞҊ ೞחѪ ޙઁܳ ݃ଢ଼ਸ ٸ যڌѱ
೧ Ѿೞח? How to automate webhacking.kr with Python © ઑӔ 2015 19
Key Point • ղо ݈ೞҊ ೞחѪ ޙઁܳ ݃ଢ଼ਸ ٸ যڌѱ
೧ Ѿೞח? • ঐޗী ח ࢎҊ җਸ ࠁৈחؘ ୡ How to automate webhacking.kr with Python © ઑӔ 2015 20
Key Point • ղо ݈ೞҊ ೞחѪ ޙઁܳ ݃ଢ଼ਸ ٸ যڌѱ
೧ Ѿೞח? • ঐޗী ח ࢎҊ җਸ ࠁৈחؘ ୡ • Ѿҗܳ ٜ݅যࢲ ױೞ? ۄחѱ ठۄ٘ীࢲ ਗ ೞחѱ ইש How to automate webhacking.kr with Python © ઑӔ 2015 21
Key Point • ղо ݈ೞҊ ೞחѪ ޙઁܳ ݃ଢ଼ਸ ٸ যڌѱ
೧ Ѿೞח? • ঐޗী ח ࢎҊ җਸ ࠁৈחؘ ୡ • Ѿҗܳ ٜ݅যࢲ ױೞ? ۄחѱ ठۄ٘ীࢲ ਗ ೞחѱ ইש • ҙ, ࢎѾ, ࢚ടঈ ١ਸ যڌѱ ೮ח ࠁৈח ѱ Point How to automate webhacking.kr with Python © ઑӔ 2015 22
زചী ਃೠ ࣽࢲ 1. ۽Ӓੋ 2. ޙઁ ࠁӝ • Highlight
ޙઁ • ۳ ޙઁ 3. ޙઁ ࣗझ ࠁӝ 4. ੋૐೞӝ How to automate webhacking.kr with Python © ઑӔ 2015 23
1. ۽Ӓੋ How to automate webhacking.kr with Python © ઑӔ
2015 24
webhacking.kr ۽Ӓੋ غয ঋਵݶ ۽Ӓੋ ಕ۽ ج۰ࠁն How to automate
webhacking.kr with Python © ઑӔ 2015 25
زചܳ ೞӝ ਤ೧ࢲח ۽Ӓੋ ࠁо ਃೣ How to automate webhacking.kr
with Python © ઑӔ 2015 26
۽Ӓੋ ࠁܳ ਬೞӝ ਤೠ ॆ ۄ࠳۞ܻо ޤо ? How
to automate webhacking.kr with Python © ઑӔ 2015 27
Violent Python ী աৡ mechanizeܳ ࢎਊೞ2 2 (http://www.yes24.com/24/goods/8433461?scode=032&OzSrank=1) How to
automate webhacking.kr with Python © ઑӔ 2015 28
۽Ӓੋ How to automate webhacking.kr with Python © ઑӔ 2015
29
ۄఠ ഛੋ How to automate webhacking.kr with Python © ઑӔ
2015 30
જই, ց۽ ೮! How to automate webhacking.kr with Python ©
ઑӔ 2015 31
Packet capture login info with wireshark How to automate webhacking.kr
with Python © ઑӔ 2015 32
ইೞ! POST method۽ id, pwܳ ੋ۽ ֈӝחҳա. How to automate
webhacking.kr with Python © ઑӔ 2015 33
Login Mechanize Source import mechanize import urllib import urlparse from
custom_source.login import id_, pw login_url = 'http://webhacking.kr/index.html?enter=1' data = urllib.urlencode({'id':id_, 'pw':pw}) browser = mechanize.Browser() resp = browser.open(login_url, data).read() How to automate webhacking.kr with Python © ઑӔ 2015 34
2. ޙઁ ࠁӝ How to automate webhacking.kr with Python ©
ઑӔ 2015 35
No. 15 • ݾ: ߄झ݀ ࣗझ ഛੋ How to automate
webhacking.kr with Python © ઑӔ 2015 36
Print source resp = browser.open(index_url).read() resp = browser.open(challenge_url).read() def join_url(url,
base_url='http://webhacking.kr'): if 'view-source:' in url: url = url.replace('view-source:', '') if 'webhacking' in url and 'http' not in url: return '{0}{1}'.format('http://', url) return urlparse.urljoin(base_url, url) def print_source(url): resp = browser.open(join_url(url)).read() print(resp) return resp print_source('challenge/javascript/js2.html') How to automate webhacking.kr with Python © ઑӔ 2015 37
print_source output How to automate webhacking.kr with Python © ઑӔ
2015 38
Colorful ೞب ঋҊ, Syntax Highlightب উغয Ҋ, Python ਬীѱח Ӓ
Ҋդҗ ҃ How to automate webhacking.kr with Python © ઑӔ 2015 39
જই, Syntax Highlightо غח Ѫ ਸ ইࠁ! How to automate
webhacking.kr with Python © ઑӔ 2015 40
Googling! How to automate webhacking.kr with Python © ઑӔ 2015
41
Pygments? ޤ?1 This is the home of Pygments. It is
a generic syntax highlighter suitable for use in code hosting, forums, wikis or other applications that need to prettify source code. Highlights are: • a wide range of over 300 languages and other text formats is supported • special attention is paid to details that increase highlighting quality How to automate webhacking.kr with Python © ઑӔ 2015 42
Pygments? ޤ?2 • support for new languages and formats are
added easily; most languages use a simple regex-based lexing mechanism • a number of output formats is available, among them HTML, RTF, LaTeX and ANSI sequences • it is usable as a command-line tool and as a library ... and it highlights even Perl 6! How to automate webhacking.kr with Python © ઑӔ 2015 43
Pygments Demo • Pygments Demo How to automate webhacking.kr with
Python © ઑӔ 2015 44
ӭՔೠؘ..? Ӕؘ Ѧ যڌѱ ղ ۽ંী ਊೞ? How to automate
webhacking.kr with Python © ઑӔ 2015 45
ীח ೧о উغ .. How to automate webhacking.kr with Python
© ઑӔ 2015 46
ৈӝӝ ҳӖ݂ ೞݶࢲ ইפ য٣ࢲ ࠌחח ӝর ա ঋ݅ ઁܳ
ও. ब ࠌ! How to automate webhacking.kr with Python © ઑӔ 2015 47
ਊೞӝ ਤೠ ࢎ ѐ֛ ਃ pygments.highlight(code, lexer, formatter, outfile=None) •
code: ਊೞҊ ೞח code • lexer: যڃ languageܳ highlight ೡ Ѫੋ?(ex: Python, C) • formatter: যڃ झఋੌਸ ࢎਊ ೡ Ѫੋ?(ex: default, friendly) • highlight: ୭ઙ ਊೡ code, lexer, formatter ҳ೧ࢲ ֍য ! How to automate webhacking.kr with Python © ઑӔ 2015 48
Pygments original source lexer = get_lexer_by_name('html') formatter = HtmlFormatter(style='default', linenos=False,
full=True) data = highlight(response, lexer, formatter) HTML(data=data) • HTML: IPython Notebookীࢲ HTMLਸ ࡸ۰ח ೡ How to automate webhacking.kr with Python © ઑӔ 2015 49
Pygments original output How to automate webhacking.kr with Python ©
ઑӔ 2015 50
য়য়য়... highlightо ػ. How to automate webhacking.kr with Python ©
ઑӔ 2015 51
Ӕؘ ই ۳ উع. How to automate webhacking.kr with Python
© ઑӔ 2015 52
Ӕؘ ই ۳ উع. ઁ ࣗझী ۳೧ח beautifierܳ ࠢৈࠁ How
to automate webhacking.kr with Python © ઑӔ 2015 53
beautifier റࠁҵ 1. original 2. jsbeautifier 3. beautifulsoup How to
automate webhacking.kr with Python © ઑӔ 2015 54
jsbeautifier & beautifulsoup How to automate webhacking.kr with Python ©
ઑӔ 2015 55
beautifier റࠁҵ ޙઁ 1. original: ࣗझ ۳ উؽ 2. jsbeautifier:
indent ؽ, tag ࢎী space ٜযо ח ޙઁ. • ৡۄੋ Online JavaScript beautifierח ۠ ޙ ઁ হחؘ ޤо ޙઁੌө? issue ৢܿ 3. beautifulsoup: script উ ࣗझо indentо উؽ How to automate webhacking.kr with Python © ઑӔ 2015 56
Ӓ݅ ఋഈೞ... How to automate webhacking.kr with Python © ઑӔ
2015 57
Ӓ݅ ఋഈೞ... Ӓա݃ html ઁ۽ ۳ غחѦ ఖೞ 3ߣ beautifulsoup
ਸ ࢶఖೞҊ ޙઁ ಽ!! How to automate webhacking.kr with Python © ઑӔ 2015 58
No.15 Sourceীࢲ password is off_script How to automate webhacking.kr with
Python © ઑӔ 2015 59
No.15 Auth • ޙઁ: ੋૐ߉ӝ ਤ೧ ੌੌ ੑ۱೧ঠ ؽ.. ನ
ੋ How to automate webhacking.kr with Python © ઑӔ 2015 60
No. 17 • ݾ: ߄झ݀ ߸ࣻ ч ഛੋ How to
automate webhacking.kr with Python © ઑӔ 2015 61
Print Source No. 17 How to automate webhacking.kr with Python
© ઑӔ 2015 62
فو... mechanizeীࢲ javascriptܳ प೯ೡ ࣻ חо? How to automate webhacking.kr
with Python © ઑӔ 2015 63
ੌױ Python ਵ۽ ೧Ѿ೧ ࠁ! unlock = 100*10*10+100/10-10+10+50-9*8+7-6+5-4*3-2*1*10*100*10*10+100/10-10+10+... print(unlock/10) #
python2 # 999780950 # python3 # 999780930.7 python2৬ python3ח division Ѿҗо ܰ. python2ীࢲ python3৬ زੌೠ Ѿҗܳ ӝ ਤ೧ ࢲ ୶оೞ from __future__ import division How to automate webhacking.kr with Python © ઑӔ 2015 64
IPython node.jsܳ प೯೧ࢲ ಽযࠁ How to automate webhacking.kr with Python
© ઑӔ 2015 65
... য૰ٚ Python ਵ۽ ೧Ѿೞӟ ೮݅ ীח যڌѱ ೧Ѿ೧ঠ ೡ...
How to automate webhacking.kr with Python © ઑӔ 2015 66
No. 14 • ݾ: ߸ࣻ৬ ೣࣻ, onclick() ࢎਊߨ How to
automate webhacking.kr with Python © ઑӔ 2015 67
Print Source No.14 resp = print_source('webhacking.kr/challenge/javascript/js1.html') <html> ... <form name="pw">
<input type="text" name="input_pwd" /> <input type="button" value="check" onclick="ck()" /> </form> <script> function ck() { var ul=document.URL; ul=ul.indexOf(".kr"); ul=ul*30; if(ul==pw.input_pwd.value) { alert("Password is "+ul*pw.input_pwd.value); } else { alert("Wrong"); } } </script> </body> </html> How to automate webhacking.kr with Python © ઑӔ 2015 68
Chrome Development Tool & IPython ޙઁ: DOMী ೧ ࢤࢿغח document.URLਸ
ੌੌ ࠂࠢ೧ঠ ೠ. , DOMਸ ઁয೧ঠ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 69
ణॅ... ٘٣য DOM ա৳ҳա4 যڌѱ ೧Ѿ೧ঠ ೞ? 4 DOM(Document Object
Model) How to automate webhacking.kr with Python © ઑӔ 2015 70
... അө য়ݶࢲ যڃ ޙઁਸ וՙ࣑աਃ? How to automate webhacking.kr
with Python © ઑӔ 2015 71
... അө য়ݶࢲ যڃ ޙઁਸ וՙ࣑աਃ? زചೞӝ ਤೠ ҳр ࠁदաਃ?
How to automate webhacking.kr with Python © ઑӔ 2015 72
അө աఋդ ޙઁ 1. ࣗझ ࣗܳ ೠٲೠٲ ࠳ۄীࢲ ࠂࠢਸ ೧ঠೠ.
2. javascriptܳ प೯ೡ ࣻ חо? • प೯ೡ ࣻ Ҋ ೧ب ࠳ۄী ઙࣘੋ ࢚ടী ࢲח যڌѱ ೡ Ѫੋо?(ex: DOM) 3. ࠳ۄী ೠٲೠٲ ࠂࠢਸ ೧ࢲ ੋૐਸ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 73
ڂߏ ైୋ • दр: 9ਘ 4ੌ Әਃੌ ֘7द~9द • ࣗ:
ъթషૉఋਕ 2க How to automate webhacking.kr with Python © ઑӔ 2015 74
How to automate webhacking.kr with Python © ઑӔ 2015 75
Browser Controller Selenium How to automate webhacking.kr with Python ©
ઑӔ 2015 76
ք ޖट ٛࠁঠ?! How to automate webhacking.kr with Python ©
ઑӔ 2015 77
ҳӖ ࢶఖೠ Test Framework How to automate webhacking.kr with Python
© ઑӔ 2015 78
ୌ݃٣ ݈ࠁ ೠ ߣ ࠁח ѱ ؊ ի ޤೞח ֧ੋח
ݢ ࠁҊաࢲ Ҋ How to automate webhacking.kr with Python © ઑӔ 2015 79
Demo Time How to automate webhacking.kr with Python © ઑӔ
2015 80
Selenium Simple Source from urllib import quote from urlparse import
urljoin from time import sleep from selenium import webdriver driver = webdriver.Firefox() google_url = 'https://google.com/' sleep(5) driver.get(google_url) sleep(5) query = 'python' search_url = urljoin(google_url, 'search?q={}'.format(quote(query))) driver.get(search_url) sleep(10) driver.quit() How to automate webhacking.kr with Python © ઑӔ 2015 81
Why Selenium?1 • Frequent regression testing(ೞח ഥӈ పझ ) •
Rapid feedback to developers(ѐߊীѱ ࡅܲ ೖ٘ߔ) • Virtually unlimited iterations of test case execution(о࢚ਵ۽ ઁೠহ పझ ாझ प೯) • Support for Agile and extreme development methodologies(ࡅܲ ѐߊ ߑߨۿਸ ਗ) How to automate webhacking.kr with Python © ઑӔ 2015 82
Why Selenium?2 • Disciplined documentation of test cases(ӏѺ ച ػ
పझ ாझ ޙࢲച) • Customized defect reporting(ѐѐੋ ਃҳী ݏ ܻನ) • Finding defects missed by manual testing(ࣻز పझ۽ ࢤӝח Ѿೣਸ ӝ) How to automate webhacking.kr with Python © ઑӔ 2015 83
݈ ҭ য۵... UI ߡӒܳ ࡅܲ दрղী ӝ ਤ೧ࢲ పझ
ೠח ѐ֛ਵ۽ ࠁݶ ؽ ࢎਊ झషܻী ٮۄࢲ పझೞח Function Testingীب ࢎਊ ؽ դ 'Ӓ زച بҳ'۽ࢲ दпਵ۽ ߄ۄࠆ How to automate webhacking.kr with Python © ઑӔ 2015 84
ޙઁਸ द ೠ ߣ ಝࠁ. How to automate webhacking.kr with
Python © ઑӔ 2015 85
അө աఋդ ޙઁ 1. ࣗझ ࣗܳ ೠٲೠٲ ࠳ۄীࢲ ࠂࠢਸ ೧ঠೠ.
2. javascriptܳ प೯ೡ ࣻ חо? • प೯ೡ ࣻ Ҋ ೧ب ࠳ۄী ઙࣘੋ ࢚ടী ࢲח যڌѱ ೡ Ѫੋо?(ex: DOM) 3. ࠳ۄী ೠٲೠٲ ࠂࠢਸ ೧ࢲ ੋૐਸ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 86
1. ࣗझ ࣗ ࠂࠢ ޙઁ How to automate webhacking.kr with
Python © ઑӔ 2015 87
࠳ۄח যରೖ sourceܳ ߉ই৬ࢲ How to automate webhacking.kr with Python
© ઑӔ 2015 88
࠳ۄח যରೖ sourceܳ ߉ই৬ࢲ rendering ೧ח Ѫ߆ী হਗ਼ই? How to
automate webhacking.kr with Python © ઑӔ 2015 89
࠳ۄח যରೖ sourceܳ ߉ই৬ࢲ rendering ೧ח Ѫ߆ী হਗ਼ই? Ӓۧݶ ղо
sourceীࢲ ࣗܳ যয়ݶ غঋա?! How to automate webhacking.kr with Python © ઑӔ 2015 90
જই ҊҊআ! How to automate webhacking.kr with Python © ઑӔ
2015 91
Challenge Page How to automate webhacking.kr with Python © ઑӔ
2015 92
ࠁחо? How to automate webhacking.kr with Python © ઑӔ 2015
93
ࠁחо? onclick event۽ location.href ೣࣻо ഐػ. How to automate webhacking.kr
with Python © ઑӔ 2015 94
onclick event Excute a JavaScript when a button is clicked
<script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World"; } </script> <button onclick="myFunction()">Click me</button> Hello Worldо ۱ػ. How to automate webhacking.kr with Python © ઑӔ 2015 95
location.href Return the entire URL(of the current page) location.href='http://google.com' ۞ݶ
ಕо ҳӖ۽ زೠ. How to automate webhacking.kr with Python © ઑӔ 2015 96
೧ࢳೞݶ onclick="location.href='challenge/web/web-01/'" click eventо ߊࢤ೮ਸ ٸ http://webhacking.kr/challenge/web/web-01/ ಕ۽ زೠ. You
got it? How to automate webhacking.kr with Python © ઑӔ 2015 97
Ӓۧݶ... onclick ࣘࢿਸ ୶ೠ റী location.href ࣘࢿਸ ୶ೞݶ challenge/web/web-01/
݅ যח ݈ॹ? How to automate webhacking.kr with Python © ઑӔ 2015 98
࢚ࣗܳ ୶ೞӝ ਤ೧ࢲח DOMਸ ઁয೧ঠ غחؘ DOMਸ যڌѱ ઁয೧ঠ غחѢջ?
How to automate webhacking.kr with Python © ઑӔ 2015 99
XPath XPath(XML Path Language)ח W3C ળਵ۽ ഛ ࢤࢿ য ޙࢲ
ҳઑܳ ా೧ ҃۽ ਤী ೠ ҳޙਸ ࢎ ਊೞৈ ೦ݾਸ ߓೞҊ ܻೞח ߑߨਸ ӝࣿೞח য . XML അࠁ ؊ औҊ ডয۽ غয ਵݴ, XSL ߸ജ (XSLT)җ XML द য(XPointer)ী ॳח য . XPathח XML ޙࢲ ֢٘ܳ ೞӝ ਤೞৈ ҃۽ध ਸ ࢎਊೞݴ, ࣻ ೣࣻ৬ ӝఋ ഛ оמೠ അٜ . How to automate webhacking.kr with Python © ઑӔ 2015 100
द ઁա ٯٯೠ ח য۰ਕ.. ೧ೞӝ औѱ exampleਸ ࠁ How
to automate webhacking.kr with Python © ઑӔ 2015 101
XPathܳ ഝਊೠ title ୶ How to automate webhacking.kr with Python
© ઑӔ 2015 102
title ੜ ୶ ع. //title title tagܳ //title/text()ח title text݅(ܻо
ਗೞ؍ Ѫ!) How to automate webhacking.kr with Python © ઑӔ 2015 103
݃झ۽ ନ XPath How to automate webhacking.kr with Python ©
ઑӔ 2015 104
݃झ۽ ନ XPathܳ ࠁפ ҭ য۵ѱ աఋա . html/body/table/tbody/tr[2]/td/center/center/form/table/tbody/tr[1]/td[1]/input How
to automate webhacking.kr with Python © ઑӔ 2015 105
݃झ۽ ନ XPathܳ ࠁפ ҭ য۵ѱ աఋա . html/body/table/tbody/tr[2]/td/center/center/form/table/tbody/tr[1]/td[1]/input Ѣ
оҊ ޥо ୶ೞӝۆ ҭ য۰ Ѫ э. ցޖ specific ೧. ౣ݅ ঈೞҊ ߸ഋ೧ࠁ! How to automate webhacking.kr with Python © ઑӔ 2015 106
Ӓۧݶ ઁ ࠄѺਵ۽ onclick ࣘࢿਸ ୶೧ ࠁ How to automate
webhacking.kr with Python © ઑӔ 2015 107
challenge list ୶ How to automate webhacking.kr with Python ©
ઑӔ 2015 108
XPath ഝਊ೧ࢲ onclick ࣘࢿ ୶ بঋѱ IDо ࢶఖ ػ. ۠Ѫਸ
ੜ ܻ೧ How to automate webhacking.kr with Python © ઑӔ 2015 109
ޙઁٜ input tag݅ ࢶఖؽ webhacking.kr ୨ ޙઁࣻח 66ޙઁ. ೞ݅ IDч
ઁੌ ী ನೣغ ӝ ٸޙী 67ѐ ֢٘о ୶ػ Ѫਸ ഛੋ оמ How to automate webhacking.kr with Python © ઑӔ 2015 110
ޙઁ tagٜਸ ୶೮..!! How to automate webhacking.kr with Python ©
ઑӔ 2015 111
ٜ ঌҊ ѷ݅ Ӓېب ഛੋೞח ରਗীࢲ Tag৬ Attribute৬ ରਸ ঌҊо
How to automate webhacking.kr with Python © ઑӔ 2015 112
Tag & Attribute ର Tag: form, table, tbody, tr, td
Attribute: type, onclick, style, background, color, onmouseout, onmouseover How to automate webhacking.kr with Python © ઑӔ 2015 113
@ܳ ࠢৈݶ Attribute Ӕ о מ //form/table/tbody/tr/td/input/@onclick प աب Attribute
୶ ೞח Ѫਸ ߊ ળ࠺ೞݶ ࢲ ӵ׳ও. द ߊೞחѤ ߊী ѱ ؊ ب غח ੌ How to automate webhacking.kr with Python © ઑӔ 2015 114
Ӓۢ ઁ sourceױীࢲ Parsing оמೞ۽ ࠂࠢਸ ೞ ঋইب ػ. How
to automate webhacking.kr with Python © ઑӔ 2015 115
അө աఋդ ޙઁ 1. ࣗझ ࣗܳ ೠٲೠٲ ࠳ۄীࢲ ࠂࠢਸ ೧ঠೠ.
2. javascriptܳ प೯ೡ ࣻ חо? • प೯ೡ ࣻ Ҋ ೧ب ࠳ۄী ઙࣘੋ ࢚ടী ࢲח যڌѱ ೡ Ѫੋо?(ex: DOM) 3. ࠳ۄী ೠٲೠٲ ࠂࠢਸ ೧ࢲ ੋૐਸ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 116
Ӓۢ ઁ যו ب ળ࠺о դѪ э. Selenium ਵ۽ ۽Ӓੋࠗఠ
द! How to automate webhacking.kr with Python © ઑӔ 2015 117
۽Ӓੋ ҳഅ mechanize۽ ೧ࠌחؘ Selenium ܲ ߑध. How to automate
webhacking.kr with Python © ઑӔ 2015 118
Selenium ܻо ੌ߈ਵ۽ Browserܳ ࢎਊೞח ߑधҗ ڙэ ࢎਊೞݶ ػ. How
to automate webhacking.kr with Python © ઑӔ 2015 119
Login Logic 1. Connect Login Webpage How to automate webhacking.kr
with Python © ઑӔ 2015 120
Login Logic 1. Connect Login Webpage 2. Input ID How
to automate webhacking.kr with Python © ઑӔ 2015 121
Login Logic 1. Connect Login Webpage 2. Input ID 3.
Input PW How to automate webhacking.kr with Python © ઑӔ 2015 122
Login Logic 1. Connect Login Webpage 2. Input ID 3.
Input PW 4. Click Login button How to automate webhacking.kr with Python © ઑӔ 2015 123
webhacking.kr Login Analysis <form method="post" action="index.html?enter=1" name="lf" onkeypress="if(event.keyCode==13)go();"> </form> function
go() { if(lf.id.value=="") { lf.id.focus(); return; } if(lf.pw.value=="") { lf.pw.focus(); return; } lf.submit(); } How to automate webhacking.kr with Python © ઑӔ 2015 124
webhacking.kr Login Analysis <form method="post" action="index.html?enter=1" name="lf" onkeypress="if(event.keyCode==13)go();"> </form> function
go() { if(lf.id.value=="") { lf.id.focus(); return; } if(lf.pw.value=="") { lf.pw.focus(); return; } lf.submit(); } ۽Ӓੋ ೞ۰ݶ javascriptܳ ॄঠغ֎?! How to automate webhacking.kr with Python © ઑӔ 2015 125
ਃೠ ೣٜࣻ ݢ Import # built-in import urllib import urlparse
import re import time # third-party import jsbeautifier import mechanize from selenium import webdriver from BeautifulSoup import BeautifulSoup as bs from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters.html import HtmlFormatter from IPython.display import HTML # custom from custom_source.login import id_, pw login_url = 'http://webhacking.kr/index.html?enter=1' index_url = 'http://webhacking.kr/index.php' challenge_url = 'http://webhacking.kr/index.php?mode=challenge' auth_url = 'http://webhacking.kr/index.php?mode=auth' How to automate webhacking.kr with Python © ઑӔ 2015 126
Login ҳഅ Source from urllib import quote from urlparse import
urljoin from time import sleep from selenium import webdriver WAIT = 1 driver = webdriver.Firefox() sleep(WAIT) driver.get(login_url) sleep(WAIT) sleep(WAIT) driver.find_element_by_name('id').send_keys(id_) driver.find_element_by_name('pw').send_keys(pw) driver.execute_script('go();') # javascript प೯೧ࢲ ۽Ӓੋ! sleep(10) driver.quit() How to automate webhacking.kr with Python © ઑӔ 2015 127
Demo Time How to automate webhacking.kr with Python © ઑӔ
2015 128
Login ҳഅೞݶࢲ javascript ޙઁө ೧Ѿ! How to automate webhacking.kr with
Python © ઑӔ 2015 129
അө աఋդ ޙઁ 1. ࣗझ ࣗܳ ೠٲೠٲ ࠳ۄীࢲ ࠂࠢਸ ೧ঠೠ.
2. javascriptܳ प೯ೡ ࣻ חо? • प೯ೡ ࣻ Ҋ ೧ب ࠳ۄী ઙࣘੋ ࢚ടী ࢲח যڌѱ ೡ Ѫੋо?(ex: DOM) 3. ࠳ۄী ೠٲೠٲ ࠂࠢਸ ೧ࢲ ੋૐਸ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 130
ઁ ੋૐ݅ ೧Ѿೞݶ ػ! How to automate webhacking.kr with Python
© ઑӔ 2015 131
Auth Analysis <form method="post" action="?mode=auth_go"> <table> <tbody> <tr> <td>Flag</td> <td>
<input type="text" name="answer" size="100"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Submit"> <br><br> Do not brute-force </td> </tr> </tbody> </table> </form> How to automate webhacking.kr with Python © ઑӔ 2015 132
Auth ҳഅ Source sleep(WAIT) driver.get(auth_url) sleep(WAIT) sleep(WAIT) answer = 'off_script'
driver.find_element_by_name('answer').send_keys(answer) # nameਵ۽ب ࢶఖ оמ # css selector۽ب ࢶఖ оמ driver.find_elements_by_css_selector('form table tbody tr td input')[-1].click() sleep(WAIT) sleep(10) driver.switch_to.alert.accept() # ਃ! alertହ হগঠ ೠ! sleep(10) How to automate webhacking.kr with Python © ઑӔ 2015 133
Demo Time How to automate webhacking.kr with Python © ઑӔ
2015 134
അө աఋդ ޙઁ 1. ࣗझ ࣗܳ ೠٲೠٲ ࠳ۄীࢲ ࠂࠢਸ ೧ঠೠ.
2. javascriptܳ प೯ೡ ࣻ חо? • प೯ೡ ࣻ Ҋ ೧ب ࠳ۄী ઙࣘੋ ࢚ടী ࢲח যڌѱ ೡ Ѫੋо?(ex: DOM) 3. ࠳ۄী ೠٲೠٲ ࠂࠢਸ ೧ࢲ ੋૐਸ ೠ. How to automate webhacking.kr with Python © ઑӔ 2015 135
റ... ٘٣য ޙઁਸ ݽف ೧Ѿ೮. How to automate webhacking.kr with
Python © ઑӔ 2015 136
ੌױ ޙઁ ೧Ѿع݅ How to automate webhacking.kr with Python ©
ઑӔ 2015 137
ੌױ ޙઁ ೧Ѿع݅ ࢎਊೞӝ ಞೠ ېझ۽ ߸ജ೧ঠ ೠ. How to
automate webhacking.kr with Python © ઑӔ 2015 138
ੌױ ޙઁ ೧Ѿع݅ ࢎਊೞӝ ಞೠ ېझ۽ ߸ജ೧ঠ ೠ. Refactoring दр
How to automate webhacking.kr with Python © ઑӔ 2015 139
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ How
to automate webhacking.kr with Python © ઑӔ 2015 140
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ 2.
view_challenge: challenge.html ਸ य೧ࢲ ޙ ઁٜ ࣗ ୶ How to automate webhacking.kr with Python © ઑӔ 2015 141
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ 2.
view_challenge: challenge.html ਸ य೧ࢲ ޙ ઁٜ ࣗ ୶ 3. print_problem_source: ࣗझ ۱ How to automate webhacking.kr with Python © ઑӔ 2015 142
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ 2.
view_challenge: challenge.html ਸ य೧ࢲ ޙ ઁٜ ࣗ ୶ 3. print_problem_source: ࣗझ ۱ 4. print_index_phps: ޙઁ ಕ উ ࣗझ ۱ How to automate webhacking.kr with Python © ઑӔ 2015 143
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ 2.
view_challenge: challenge.html ਸ य೧ࢲ ޙ ઁٜ ࣗ ୶ 3. print_problem_source: ࣗझ ۱ 4. print_index_phps: ޙઁ ಕ উ ࣗझ ۱ 5. auth: ੋૐ ಕ How to automate webhacking.kr with Python © ઑӔ 2015 144
Refactoring 1. login: login ҳഅ. ࢎਊ id, pw ੑ۱ 2.
view_challenge: challenge.html ਸ य೧ࢲ ޙ ઁٜ ࣗ ୶ 3. print_problem_source: ࣗझ ۱ 4. print_index_phps: ޙઁ ಕ উ ࣗझ ۱ 5. auth: ੋૐ ಕ 6. accept_alert: ੋૐ ಕীࢲ ഛੋ ߡౡ ܼೞӝ How to automate webhacking.kr with Python © ઑӔ 2015 145
Class & Methods class webHacking(object): def __init__(self): def __del__(self): def
login(self): def view_challenge(self): def print_problem_source(self, num): def print_index_phps(self, src='index.phps'): def auth(self, answer): def accept_alert(): How to automate webhacking.kr with Python © ઑӔ 2015 146
Mechanize एয! How to automate webhacking.kr with Python ©
ઑӔ 2015 147
Ӕؘ וԕա..? How to automate webhacking.kr with Python © ઑӔ
2015 148
ࠗఠ ۧѱ ࢜ח ҳઑо աৡѤ ইפঠ. ೞࠁפө ۧѱ ೞݶ
ಞೡѪ эইࢲ աৡ ҳઑ.. , ࢤп ޛ How to automate webhacking.kr with Python © ઑӔ 2015 149
Demo Time How to automate webhacking.kr with Python © ઑӔ
2015 150
ղо ҕࠗೠ Resources 1. Selenium with Python 2. Selenium Testing
Tools Cookbook How to automate webhacking.kr with Python © ઑӔ 2015 151
ನހ ࢎ ನހझఠ ߬झਤद दો2 23ച ࢎషद పஎ!
࠺ ߽ӝ ࢎਖ਼٘ۄ!! ܻ࠭ ನހझఠ ߬झਤद दો2 24ച Ѿ गܻӒ! How to automate webhacking.kr with Python © ઑӔ 2015 152
ࢎ ध • ध হਵݶ ষդ ز߈ೣ! •
virtualenv • pip How to automate webhacking.kr with Python © ઑӔ 2015 153
աী ୶оೡ ղਊٜ • print_problem_source, print_index_phps ࢸݺ (ppt ݅٘ח दр
Ԩ ݆ ٚ. 40दр ب ॵ٠.) • Proxy ਊ೧ࢲ ۄఠ ߸ઑ(ѱ ઁੌ х উ ൩) • য ࣻ হ Fiddlerա Burp Suiteܳ ॄঠೡ٠ • XSS • SQL Injection • sqlmap How to automate webhacking.kr with Python © ઑӔ 2015 154
хࢎפ How to automate webhacking.kr with Python © ઑӔ 2015
155
Q&A How to automate webhacking.kr with Python © ઑӔ 2015
156
݄݃ ೖஉѦ ૢߑ How to automate webhacking.kr with Python ©
ઑӔ 2015 157