Skip to content

Instantly share code, notes, and snippets.

@youwei0505
Created September 29, 2020 07:22
Show Gist options
  • Save youwei0505/c51d96bc0472bb0c10a214818a72e67a to your computer and use it in GitHub Desktop.
Save youwei0505/c51d96bc0472bb0c10a214818a72e67a to your computer and use it in GitHub Desktop.
tags title
CTF
Crypto CTF 工具

https://www.slideshare.net/SiChenLin/simple-crypto

[TOC]

Encoding / Decoding

URL編碼 (又稱 Percent-encoding)

講義

  • ASCII control characters

  • Non-ASCII control characters

  • 保留字元 (reserved characters)

    • 有特殊目的,因此需使用百分比編碼
  • 未保留字元 (unreserved characters)

古典密碼學

Substitution cipher

Shift cipher(=Transposition Cipher = Caesar Cipher)(https://planetcalc.com/1434/)

Vigenère Cipher 維吉尼亞加密法

  • Table
  • Cipher Key
  • Online tool
    • 有key沒key都可以破解

編碼

ASCII

  • ASCII table
  • 轉換
ord('A') # 65
ord('a') # 97
chr(97) # a
chr(65) # A

bin(20) # 0b10010 十進制轉二進制
oct(20) # 0o24 十進制轉八進制
hex(20) # 0x14 十進制轉十六進制
import base64
message = b'Hi CDPA owo' # plaintext
ciphertext = base64.b64encode(message)
plaintext = base64.b64decode(ciphertext)

HASH

MD5

SHA1

Step by Step 高次方計算餘數之方法 CTF RSA 各種解法

from Crypto.Util.number import *     #引入需要的套件

e = 
n = 
c = 

fn = (q-1) * (p-1)
d = inverse(e, fn)      # ed mod fn = 1

m = pow(c, d, n)        # (c^d) % n
print(m)

print("---------------")

m = long_to_bytes(m)
print(m)
from Crypto.PublicKey import RSA  #讀公鑰
from Crypto.Util.number import *  #計算

key = RSA.importKey(open("PCTF/pubkey.pem" , "rb").read()) # 讀取 pubkey.pem

n = key.n
e = key.e

print(key.n)
print(key.e)
print("-----------")

#取密文
c = open("PCTF/flag.enc", "rb").read()
# print(c)
c = bytes_to_long(c)

# 用 factordb.com 因數分解
p = 275127860351348928173285174381581152299
q = 319576316814478949870590164193048041239

#歐拉函數
phi_n = (p-1) * (q-1)

#模反函數
d = inverse(e , phi_n)

#解密
m = pow(c, d, n)
print(long_to_bytes(m))

Hash

MD5

SHA1 (Secure Hash Algorithm-1)

其他

TOOL

  • john (in kali)
    • $ john -show shadow
---
tags: CTF
title: 資安比賽
---
# 金盾獎
## 參考資料
* [2016初賽](https://bookgin.tw/2016/10/15/2016-%E9%87%91%E7%9B%BE%E7%8D%8E-%E5%88%9D%E8%B3%BD%E5%BF%83%E5%BE%97/)
* [2017決賽](https://www.duckll.tw/2017/12/106.html)
* [2017題目](https://github.com/DuckLL/106_shielda_backup)
## [CTF](https://hackmd.io/ng7Fw1TWTq-KkH2EpPgORA)
### 領域
* [Web](/KzhsQMS4QiG6a516zqNl5w)
* [Reverse Engineering](/uIkZazmFQcKIvCoLfX8SJA)
* [Crypto](/SYI5N2FURiedP_J8hSgwEQ)
### 工具
* [GDB](https://hackmd.io/2RxpGAw3QZ6ALHNF5pPaog)
# [資訊安全]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment