SlideShare a Scribd company logo
1 of 47
Download to read offline
Learn Python in 30 min -3
cmj
1
接下來要教大家的是
2
3
• 沒有控制,你就不能
• 同時操作兩台以上機器
• 機器間的互動行為
• 擬人操作
4
• 遠端控制有很多種
• 遠端指令 (Remote Command)
• 遠端桌面 (Remote DeskTop)
5
• 遠端控制有很多種
• 遠端指令 (Remote Command)
• 遠端桌面 (Remote DeskTop)
• 但這不是我們要的
6
• 除非
• 你想要利用程式得到 UI 訊息
• 你想要確定 I/O 功能正常
• 或者你是真的要測試遠端桌面可以用
7
• 所以我們需要的是:遠端操作機器,就跟在 local 一樣
• 遠端物件 (Remote Object)
• 操作的是程式碼
• 程式碼在 remote 執行 === local 執行
8
• 像是
• 開檔案
• 判斷檔案在不在
• 確定現在使用者身份
• … etc
9
這樣的好處?
10
遠端機器 === 你程式的參數
11
所以你需要的是...
12
• 定義一個函數:邏輯依舊,但是
• 機器變成參數的一部分
• 你可以一口氣在 n (n>2) 台機器上跑
• 輪流在個別機器執行
• 結果回存在執行的機器上
13
14
• PyRO (Python Remote Object)
• 好用的第三方套件
• 部署在支援 Python 的機器上
• 幾乎平台無關
15
• 兩個部分
• Server - 發出指令
• 指定特定一台 client 的特定 object
• 給予參數執行並且得到結果
• Client - 接受指令
• 公開很多 object
• 等待指令執行
16
• Server
• 我想要 client A 的 whoAmI 指令
• 表示我想呼叫 client A 的 whoAmI method
• Client
• 公開 whoAmI 指令
• 等著 server 說:我想要知道你是誰
17
• Client Side 有以下重點
• 必須只能 exposed object
• Server 只能呼叫 object 的 method
• 要注意生命週期∼
18
• Client Side 有以下重點
• 必須只能 exposed object
• Server 只能呼叫 object 的 method
• 要注意生命週期∼ 開發的人腦海要有這句話
19
Client Side
20
Client Side
21
公開的物件
• 執行 client.py 之後
• 會隨機產生一個聽 localhost 的 socket
• 有相對應的 URI
• Server 靠這個 URI 來判斷是哪一個 client
22
run client.py
23
• Server Side 有以下重點
• 確定這個 client exposed obj 的 URI 是對的
• 了解 client exposed 的 object 有啥能力
(method)
• dir 在這時候是有用的 !
24
Server Side
25
26
執⾏行的結果
⽤用 dir 來偷看能⼒力
但是這樣很不方便
27
• 每次都要記錄 client 的 URI:沒人這麼無聊
• 每次都只能在 localhost:我就是要多台機器互動
28
其實 Document 有教你
29
• 注意看 Pyro4.Daemon / Pyro4.register 的 help
• 表示 client 有自己的名稱:通常是IP:PORT
• 相對的,object 也有相對也有特定的 URI
• 就叫做 PYRO:OBJECT_NAME@IP:PORT
30
重要的是...
31
已經有人包成函示庫了
32
33
• 我已經寫成一個類別
• 你選擇需要 exposed object 就會處理後續工作,包含
• 聽特定的 Port
• exposed 成固定的 FORMAT
34
35
新增/刪除物件
36
實際註冊物件/執⾏行 client
37
實際註冊物件
38
執⾏行 client 程式
• 這樣,你就可以根據
• 定義得 FORMAT 來使用 Remote Object
• 像是
• FORMAT = PYRO:obj_{name}@IP:PORT
• name 是原本 class 該有的名稱
• Pyro4.Proxy(“PYRO:obj_{name}@{host}:{port}”)
39
這樣,一切又變成函數了>.^
40
又不免俗的
41
• Pyro 真的博大精深
• 不過不用讀完 document
• 相對的,需要思考到底需要哪些遠端操作
• 而這些是程式可以完成的
42
不然我也希望有程式可以幫我寫扣
43
簡單的 Client/Server
• Client 可以完成一件功能
• exposed 一個可以使用的 object
• 不能是 Slides 上的範例
• 固定一個 object 的 URI
• Server 可以
• 根據 client 的 IP,就可以使用 remote object
44
複雜的 Client/Server
• 多個 Client / 一個 Server 架構
• Client
• Exposed object:目前機器的運行時間 (Second)
• Exposed object:目前剩餘的使用空間 (MB)
• Server
• 給定所有 Client IP
• 找到運行最久的機器
• 全部機器的剩餘空間
45
• Ref
• Pyro [https://pythonhosted.org/Pyro4/]
46
Thanks for your attentions
47

More Related Content

Similar to Learn python in 30 min - 3

Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用勇浩 赖
 
Net 相依性注入 學習筆記 1.0
Net 相依性注入 學習筆記 1.0Net 相依性注入 學習筆記 1.0
Net 相依性注入 學習筆記 1.0智興 陳
 
Binary exploitation - AIS3
Binary exploitation - AIS3Binary exploitation - AIS3
Binary exploitation - AIS3Angel Boy
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 
為什麼 App 卡卡的
為什麼 App 卡卡的為什麼 App 卡卡的
為什麼 App 卡卡的鈺翔 林
 
04 Delegation and Core Location
04 Delegation and Core Location04 Delegation and Core Location
04 Delegation and Core LocationTom Fan
 
Elastic stack day-1
Elastic stack day-1Elastic stack day-1
Elastic stack day-1YI-CHING WU
 
Ch3 basic command(2013 ncu-nos_nm)
Ch3   basic  command(2013 ncu-nos_nm)Ch3   basic  command(2013 ncu-nos_nm)
Ch3 basic command(2013 ncu-nos_nm)Kir Chou
 
使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)Max Lai
 

Similar to Learn python in 30 min - 3 (9)

Python 于 webgame 的应用
Python 于 webgame 的应用Python 于 webgame 的应用
Python 于 webgame 的应用
 
Net 相依性注入 學習筆記 1.0
Net 相依性注入 學習筆記 1.0Net 相依性注入 學習筆記 1.0
Net 相依性注入 學習筆記 1.0
 
Binary exploitation - AIS3
Binary exploitation - AIS3Binary exploitation - AIS3
Binary exploitation - AIS3
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
為什麼 App 卡卡的
為什麼 App 卡卡的為什麼 App 卡卡的
為什麼 App 卡卡的
 
04 Delegation and Core Location
04 Delegation and Core Location04 Delegation and Core Location
04 Delegation and Core Location
 
Elastic stack day-1
Elastic stack day-1Elastic stack day-1
Elastic stack day-1
 
Ch3 basic command(2013 ncu-nos_nm)
Ch3   basic  command(2013 ncu-nos_nm)Ch3   basic  command(2013 ncu-nos_nm)
Ch3 basic command(2013 ncu-nos_nm)
 
使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)
 

More from Chia-Hao Tsai

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001Chia-Hao Tsai
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - ormChia-Hao Tsai
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301Chia-Hao Tsai
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102Chia-Hao Tsai
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101Chia-Hao Tsai
 
[2017.03.18] hst binary training part 1
[2017.03.18] hst binary training   part 1[2017.03.18] hst binary training   part 1
[2017.03.18] hst binary training part 1Chia-Hao Tsai
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitChia-Hao Tsai
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionChia-Hao Tsai
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4Chia-Hao Tsai
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introductionChia-Hao Tsai
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)Chia-Hao Tsai
 
Security coding c and c++ ch8 (1)
Security coding c and c++   ch8 (1)Security coding c and c++   ch8 (1)
Security coding c and c++ ch8 (1)Chia-Hao Tsai
 

More from Chia-Hao Tsai (18)

[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001[2019.05] HST - RegEx 101 ~ 1001
[2019.05] HST - RegEx 101 ~ 1001
 
[2019.02.16] hst - orm
[2019.02.16] hst  - orm[2019.02.16] hst  - orm
[2019.02.16] hst - orm
 
[2019.01.12] hst iptables 101 to 301
[2019.01.12] hst   iptables 101 to 301[2019.01.12] hst   iptables 101 to 301
[2019.01.12] hst iptables 101 to 301
 
[2018.12.15] hst python object 102
[2018.12.15] hst   python object 102[2018.12.15] hst   python object 102
[2018.12.15] hst python object 102
 
[2018.11.16] Python Object 101
[2018.11.16]  Python Object 101[2018.11.16]  Python Object 101
[2018.11.16] Python Object 101
 
[2017.03.18] hst binary training part 1
[2017.03.18] hst binary training   part 1[2017.03.18] hst binary training   part 1
[2017.03.18] hst binary training part 1
 
Rootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based RootkitRootkit 102 - Kernel-Based Rootkit
Rootkit 102 - Kernel-Based Rootkit
 
Rootkit 101 - 2nd Edition
Rootkit 101 - 2nd EditionRootkit 101 - 2nd Edition
Rootkit 101 - 2nd Edition
 
ELF 101
ELF 101ELF 101
ELF 101
 
Maker - WiFi AP
Maker - WiFi APMaker - WiFi AP
Maker - WiFi AP
 
Learn Python in 30 min - 4
Learn Python in 30 min - 4Learn Python in 30 min - 4
Learn Python in 30 min - 4
 
Learn python 1
Learn python 1Learn python 1
Learn python 1
 
HoneyCon 2014
HoneyCon 2014HoneyCon 2014
HoneyCon 2014
 
Passwd crack introduction
Passwd crack   introductionPasswd crack   introduction
Passwd crack introduction
 
Security coding c and c++ ch8(2)
Security coding c and c++   ch8(2)Security coding c and c++   ch8(2)
Security coding c and c++ ch8(2)
 
Security coding c and c++ ch8 (1)
Security coding c and c++   ch8 (1)Security coding c and c++   ch8 (1)
Security coding c and c++ ch8 (1)
 
Build web server
Build web serverBuild web server
Build web server
 
Rootkit tw(0224)
Rootkit tw(0224)Rootkit tw(0224)
Rootkit tw(0224)
 

Learn python in 30 min - 3