RockPaperScissors
- Description
๊ฐ์๋ฐ์๋ณด ๊ฒ์์ ๊ธฐ๋ฅ์ด ์๋ ํ์ด์ง์ด๋ค.
sorcecode๋ฅผ ๋ณผ ์ ์๋๋ก ํ์๋๋ฐ, ์์ค์ฝ๋๋ ์๋์ฒ๋ผ ๊ตฌ์ฑ๋์ด์๋ค.
# !/usr/bin/python
# [Game source]
# https://codereview.stackexchange.com/questions/172337/rock-paper-scissors-game-in-python
import random
import sys
def playGame():
flag = fopen("flag", "r");
usr_choice = input()
'''
cpu_random = random.randint(1,3)
cpu_choice = cpu_random
'''
if usr_choice == "Rock":
cpu_random = 2
elif usr_choice == "Paper":
cpu_random = 3
elif usr_choice == "Scissors":
cpu_random = 1
else:
cpu_random = 0
if cpu_random == 1:
cpu_choice = "Rock"
elif cpu_random == 2:
cpu_choice = "Paper"
elif cpu_random == 3:
cpu_choice = "Scissors"
else:
cpu_choice = "Invalid Input!!"
if usr_choice == cpu_choice:
result = "Tie -_-"
elif usr_choice == "Rock" and cpu_choice == "Paper":
result = "You Lose :("
elif usr_choice == "Rock" and cpu_choice == "Scissors":
result = "You Win :)" + flag
elif usr_choice == "Paper" and cpu_choice == "Scissors":
result = "You Lose :("
elif usr_choice == "Paper" and cpu_choice == "Rock":
result = "You Win :)" + flag
elif usr_choice == "Scissors" and cpu_choice == "Rock":
result = "You Lose :("
elif usr_choice == "Scissors" and cpu_choice == "Paper":
result = "You Win :)" + flag
else:
result = "You Lose :("
out_text = "Your choice is " + usr_choice + "./"
out_text += "Computer\'s choice is " + cpu_choice + "!/"
out_text += result
print (out_text)
if __name__ == "__main__":
playGame()
์ฌ์ฉ์์ ์ ๋ ฅ์ input() ํจ์๋ก ๋ฐ์์ ์ฒ๋ฆฌํ๊ณ , ๊ฒ์์์ ์ ๋ ์ด๊ธธ ์ ์๊ฒ ์ฌ์ฉ์์ ์ ๋ ฅ์ ๋ฐ๋ผ ์นด์ดํฐ๋ฅผ ์น๊ณ ์๋ค.
usr_choice๋ฅผ input() ํจ์๋ก ๋ฐ๋๋ฐ ํด๋น ํจ์์์ ์ทจ์ฝ์ ์ด ์กด์ฌํ๋ค.
์๋ ๋งํฌ๋ฅผ ๋ณด๋ฉด
https://medium.com/@abdelazimmohmmed/python-input-vulnerability-30b0bfea22c9
์ฌ์ฉ์๊ฐ input() ํจ์์ ์ ๋ ฅํ ๋ฐ์ดํฐ๊ฐ ์ธ์๋์ด ์คํ์ด๋๋ ์ทจ์ฝ์ ์ด ์กด์ฌํ๋ค๋๊ฑธ ์ ์ ์๋ค.
ํด๋น ์ทจ์ฝ์ ์ ์ด์ฉํด system ํจ์๋ฅผ ํตํด ls ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ์๋์ฒ๋ผ ๋ช ๋ น์ด๊ฐ ์ํ์ด ๋๋ค.
์ด์ flag ํ์ผ์ ์์น๋ฅผ ์ฐพ์์ flag๋ฅผ ํ์ธํ๋ฉด ๋๋ค.
- Mitigation
input() ํจ์๋ฅผ ํตํด ์ฌ์ฉ์๊ฐ ์ ๋ ฅํ ๊ฐ์ด ๊ทธ๋๋ก ํด์์ด๋๋ ๋ถ๋ถ์ด ์ทจ์ฝํ๋ค.
ํด๋น ํจ์๋ฅผ raw_input() ํจ์๋ก ๋ณ๊ฒฝํ์ฌ ์ฌ์ฉ์ ์ ๋ ฅ์ str์ผ๋ก๋ง ๋ฐ์ ์ ์๋๋ก ํ๋ค.
๋๊ธ
์ด ๊ธ ๊ณต์ ํ๊ธฐ
-
๊ตฌ๋
ํ๊ธฐ
๊ตฌ๋ ํ๊ธฐ
-
์นด์นด์คํก
์นด์นด์คํก
-
๋ผ์ธ
๋ผ์ธ
-
ํธ์ํฐ
ํธ์ํฐ
-
Facebook
Facebook
-
์นด์นด์ค์คํ ๋ฆฌ
์นด์นด์ค์คํ ๋ฆฌ
-
๋ฐด๋
๋ฐด๋
-
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
๋ค์ด๋ฒ ๋ธ๋ก๊ทธ
-
Pocket
Pocket
-
Evernote
Evernote