0w0
[primalsecurity] 0x0 – Getting Started Pt.2 본문
Primalsecurity/Primalsecurity_Python-tutorials
[primalsecurity] 0x0 – Getting Started Pt.2
0w0 2019. 12. 17. 11:16728x90
반응형
Python Skeleton Script (파이썬 스켈레톤 스크립트)
스크립트 기본 구조
1
2
3
4
5
6
7
8
9
|
import <module1>, <module2>
def myFunction():
def main():
myFunction()
if __name__=="__main__":
main()
|
Functions (함수)
함수의 기본 pseudocode
1
2
3
4
5
6
7
8
|
# Declare function/setup logic
def MyFunction:
...do work...
return output
#Call the function from main:
def main():
output = MyFunction(input)
|
Classes (클래스)
데이터 및 정의의 논리적 분류, 그룹화를 한 것이 클래스
클래스에는 속성 및 메소드를 가질 수 있음
해당 클래스를 상속하여 클래스 객체를 만듦 (객체 지향 프로그래밍)
Domain Class 예시
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
>>> import os
>>> class Domain:
... def __init__(self,domain,port,protocol):
# Stores the variabled passed inside two variables
... self.domain=domain
... self.port=port
... self.protocol=protocol
# Defines a method to build a URL
... def URL(self):
... if self.protocol == 'https':
... URL='https://'+self.domain+':'+self.port+'/'
... if self.protocol == 'http':
... URL='http://'+self.domain+':'+self.port+'/'
... return URL
... def lookup(self):
... os.system("nslookup"+self.domain)
...
>>>
>>> domain=Domain('google.com','443','https')
>>>
>>> dir(domain)
['URL', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__
', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__
le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr_
_', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'domain', 'l
ookup', 'port', 'protocol']
>>>
>>> domain.URL()
'https://google.com:443/'
>>> domain.port
'443'
>>> domain.protocol
'https'
>>>
|
Domain 클래스의 인스턴스
Handling CLI Arguments with “sys” (“sys”를 사용하여 CLI 인수 처리 )
sys 모듈을 사용해서 명령 인수를 스크립트 변수로 가져옴.
sys.agrv
1
2
3
4
5
6
7
8
|
import sys
script = sys.argv[0]
ip = sys.argv[1]
port = sys.argv[2]
print("[+] The script name is: "+script)
print("[+] The IP is: "+ip+" and the port is: "+port)
|
CLI 환경에서 입력값을 인자값으로 넣어서 스크립트 실행
실행형태
1
2
3
|
~$ python sys.py 8.8.8.8 53
[+] The script name is: sys.py
[+] The IP is: 8.8.8.8 and the port is: 53
|
728x90
반응형
'Primalsecurity > Primalsecurity_Python-tutorials' 카테고리의 다른 글
[primalsecurity] 0x3 – Fuzzer (0) | 2019.12.21 |
---|---|
[primalsecurity] 0x2 – Reverse Shell (0) | 2019.12.19 |
[primalsecurity] 0x1 – Port Scanner (0) | 2019.12.18 |
[primalsecurity] 0x0 – Getting Started (0) | 2019.12.14 |
[primalsecurity] 0x00 - python tutorials (0) | 2019.12.10 |
Comments