0w0
[primalsecurity] 0x0 – Getting Started 본문
[primalsecurity] 0x0 – Getting Started
0w0 2019. 12. 14. 07:43primalsecurity의 예시 실습 환경 : using a Linux OS and using Python version 2.x
난 : using a Win OS and using Python version 3.6.x
The Python Interpreter (파이썬 인터프리터)
터미널이나 프롬프트에 python 입력
1
2
3
4
5
|
D:\hello>python
Python 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
|
파이썬 인터프리터에 직접 입력이 가능해짐
두 개의 변수를 정의하고 type () 함수를 사용하여 문자열과 정수 type 확인
1
2
3
4
5
6
7
8
9
|
>>> ip='8.8.8.8'
>>> port=53
>>>
>>> type(ip)
<class 'str'>
>>>
>>> type(port)
<class 'int'>
>>>
|
내장 함수인 help() 를 이용하여 임의의 함수의 정보 및 기능 탐색이 가능
>>> help(type)
Help on class type in module builtins:
class type(object)
| type(object_or_name, bases, dict)
| type(object) -> the object's type
| type(name, bases, dict) -> a new type
|
| Methods defined here:
|
| __call__(self, /, *args, **kwargs)
| Call self as a function.
(...생략)
str() 함수를 사용하여 정수 type을 문자열 type으로 변경
1
2
|
>>> print("The IP is : "+ip+" and the prot is: "+str(port))
The IP is : 8.8.8.8 and the prot is: 53
|
len() 함수를 사용하여 문자열 길이 확인
1
2
3
4
5
6
7
8
9
10
11
12
|
>>> domain='primalsecurity.net'
>>> domain
'primalsecurity.net'
>>> domain[0]
'p'
>>> domain[0:3]
'pri'
>>> domain[1:]
'rimalsecurity.net'
>>>
>>> len(domain)
18
|
dir() 함수를 사용하여 내장함수 조회
1
2
3
4
5
6
7
8
9
10
11
12
|
>>> dir(ip)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__
format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash
__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__
rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefol
d', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map',
'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeri
c', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'ma
ketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstr
ip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper
', 'zfill']
|
help() 함수로 정보 조회, split 사용
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
>>> help(ip.split)
Help on built-in function split:
split(...) method of builtins.str instance
S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
>>> string=ip+':'+str(port)
>>> string
'8.8.8.8:53'
>>>
>>> string.split(':')
['8.8.8.8', '53']
|
split() 함수를 사용해서 ':' 기준으로 list를 만듦
list는 .append(항목추가), .remove(항목제거)로 항목 추가 및 제가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
>>> list=string.split(':')
>>> list
['8.8.8.8', '53']
>>>
>>> list[0]
'8.8.8.8'
>>>
>>> list.append('google')
>>>
>>> list
['8.8.8.8', '53', 'google']
>>>
>>> list.remove('google')
>>>
>>> list
['8.8.8.8', '53']
|
Python Modules (파이썬 모듈)
파이썬은 다양한 모듈을 사용할 수 있으며, import 명령을 사용
os 모듈을 사용해서 파이썬 코드 내에서 OS 명령 수행 가능
>>> import os
>>> os.system("dir")
D 드라이브의 볼륨: 로컬 디스크
볼륨 일련 번호: 30E4-5E79
D:\hello>python 디렉터리
2019-12-14 오전 12:55 <DIR> .
2019-12-14 오전 12:55 <DIR> ..
2019-12-14 오전 06:14 <DIR> .idea
2019-12-10 오전 05:39 205 00.python tutorials.py
2019-12-14 오전 12:55 27 0x0 – Getting Started Pt.2.py
2개 파일 232 바이트
3개 디렉터리 251,251,736,576 바이트 남음
0
>>>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
>>> import os
>>> os.system("dir")
D 드라이브의 볼륨: 로컬 디스크
볼륨 일련 번호: 30E4-5E79
D:\hello>python 디렉터리
2019-12-14 오전 12:55 <DIR> .
2019-12-14 오전 12:55 <DIR> ..
2019-12-14 오전 06:14 <DIR> .idea
2019-12-14 오전 12:55 27 0x0 – Getting Started Pt.2.py
2개 파일 232 바이트
3개 디렉터리 251,251,736,576 바이트 남음
0
>>>
|
윈도우 cmd(커맨드) 명령 'dir' 사용함
Creating a File Object (파일 객체 생성)
파일 객체를 사용하여 파일 생성 및 쓰기, 읽기를 수행
1
2
3
4
5
6
7
8
|
>>> file=open('test.txt','w')
>>> file.write('hello')
5
>>> file.close()
>>> file=open('test.txt','r')
>>> file.readlines()
['hello']
>>>
|
'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 Pt.2 (0) | 2019.12.17 |
[primalsecurity] 0x00 - python tutorials (0) | 2019.12.10 |