1. 程式人生 > 其它 >Vulhub 漏洞學習之:Fastjson

Vulhub 漏洞學習之:Fastjson

sys模組

sys.argv

接受命令列傳遞的引數
第一個引數時檔名稱,後續為引數

指令碼內容:
#!/usr/bin/python3
import sys

name="hello world"
print(name)

print("-------------------------------");
print("The list of command line arguments:\n", sys.argv)

print("-------------------------------");
for i in sys.argv:
  print(i)



輸出:
[root@localhost scripts]# python3 first.py hello1 hello2
hello world
-------------------------------
The list of command line arguments:
 ['first.py', 'hello1', 'hello2']
-------------------------------
first.py
hello1
hello2

sys.platform

在linux環境下:
sys.platform  為linux

在windows環境下:
sys.platform  為win32

sys.executable

指令碼:
#!/usr/bin/python3
import sys


name="hello world"
print(name)

print("-------------------------------");
print("The list of command line arguments:\n", sys.argv)

print("-------------------------------");
for i in sys.argv:
  print(i)

print(sys.platform)

print(sys.executable)



輸出:
[root@localhost scripts]# python3 first.py hello1 hello2
hello world
-------------------------------
The list of command line arguments:
 ['first.py', 'hello1', 'hello2']
-------------------------------
first.py
hello1
hello2
linux
/usr/bin/python3

sys.modules

指令碼:
#!/usr/bin/python3
import sys


name="hello world"
print(name)

print("-------------------------------");
print("The list of command line arguments:\n", sys.argv)

print("-------------------------------");
for i in sys.argv:
  print(i)

print(sys.platform)

print(sys.executable)


print("-------------------------------");
print(sys.modules)


輸出:
[root@localhost scripts]# python3 first.py hello1 hello2
hello world
-------------------------------
The list of command line arguments:
 ['first.py', 'hello1', 'hello2']
-------------------------------
first.py
hello1
hello2
linux
/usr/bin/python3
-------------------------------
{'builtins': <module 'builtins' (built-in)>, 'sys': <module 'sys' (built-in)>, '_frozen_importlib': <module '_frozen_importlib' (frozen)>, '_imp': <module '_imp' (built-in)>, '_warnings': <module '_warnings' (built-in)>, '_thread': <module '_thread' (built-in)>, '_weakref': <module '_weakref' (built-in)>, '_frozen_importlib_external': <module '_frozen_importlib_external' (frozen)>, '_io': <module 'io' (built-in)>, 'marshal': <module 'marshal' (built-in)>, 'posix': <module 'posix' (built-in)>, 'zipimport': <module 'zipimport' (built-in)>, 'encodings': <module 'encodings' from '/usr/lib64/python3.6/encodings/__init__.py'>, 'codecs': <module 'codecs' from '/usr/lib64/python3.6/codecs.py'>, '_codecs': <module '_codecs' (built-in)>, 'encodings.aliases': <module 'encodings.aliases' from '/usr/lib64/python3.6/encodings/aliases.py'>, 'encodings.utf_8': <module 'encodings.utf_8' from '/usr/lib64/python3.6/encodings/utf_8.py'>, '_signal': <module '_signal' (built-in)>, '__main__': <module '__main__' from 'first.py'>, 'encodings.latin_1': <module 'encodings.latin_1' from '/usr/lib64/python3.6/encodings/latin_1.py'>, 'io': <module 'io' from '/usr/lib64/python3.6/io.py'>, 'abc': <module 'abc' from '/usr/lib64/python3.6/abc.py'>, '_weakrefset': <module '_weakrefset' from '/usr/lib64/python3.6/_weakrefset.py'>, 'site': <module 'site' from '/usr/lib64/python3.6/site.py'>, 'os': <module 'os' from '/usr/lib64/python3.6/os.py'>, 'errno': <module 'errno' (built-in)>, 'stat': <module 'stat' from '/usr/lib64/python3.6/stat.py'>, '_stat': <module '_stat' (built-in)>, 'posixpath': <module 'posixpath' from '/usr/lib64/python3.6/posixpath.py'>, 'genericpath': <module 'genericpath' from '/usr/lib64/python3.6/genericpath.py'>, 'os.path': <module 'posixpath' from '/usr/lib64/python3.6/posixpath.py'>, '_collections_abc': <module '_collections_abc' from '/usr/lib64/python3.6/_collections_abc.py'>, '_sitebuiltins': <module '_sitebuiltins' from '/usr/lib64/python3.6/_sitebuiltins.py'>, 'sysconfig': <module 'sysconfig' from '/usr/lib64/python3.6/sysconfig.py'>, '_sysconfigdata_m_linux_x86_64-linux-gnu': <module '_sysconfigdata_m_linux_x86_64-linux-gnu' from '/usr/lib64/python3.6/_sysconfigdata_m_linux_x86_64-linux-gnu.py'>}

sys.path

該屬性是一個由字串組成的列表,其中各個元素表示的是 Python 搜尋模組的路徑;在程式啟動期間被初始化。

其中第一個元素(也就是path[0])的值是最初呼叫 Python 直譯器的指令碼所在的絕對路徑;如果是在互動式環境下檢視sys.path的值,就會得到一個空字串。

sys.path

輸出:
['/root/scripts', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']

sys.exit

功能:執行到主程式末尾,直譯器自動退出,但是如果需要中途退出程式,可以呼叫sys.exit函式,帶有一個可選的整數引數返回給呼叫它的程式,表示你可以在主程式中捕獲對sys.exit的呼叫。(0是正常退出,其他為異常)

sys.stdin sys.stdout sys.err