我懶得再重寫一次筆記,就直接轉吧!!
將 Hackmd 中的筆記內容轉為 Gokarna 相容的顯示樣式
範例轉換來源 Example.md
1---
2lang: zh-TW
3title: "FHSH X AIS3 Club 挑戰賽 Writeup"
4tags: [ "Cyber Security", "Competition", "CTF Writeup" ]
5authors: [ "鄭", "salt", "XinShou" ]
6type: post
7showTableOfContents: true
8date: 2024-06-08
9---
10
11<!-- Hackmd Only -->
12
13# FHSH X AIS3 Club 挑戰賽 Writeup
14
15:::spoiler Categories
16[TOC]
17:::
18<!-- /Hackmd Only -->
19
20> Team – [ntihs](https://ctfd.fhh4ck3rs.taipei/teams/16)
21> Member – cheng, salt, wasami, xinshou
22
23---
24
25:::spoiler Scoreboard/Challenge
26![Scoreboard](https://hackmd.io/_uploads/S19f1-_rR.png)
27![Challenges](https://hackmd.io/_uploads/BJJWyZuSA.png)
28:::
29
30---
31
32## MISC
33
34### Welcome
35
36> :::spoiler 原圖
37> ![Challenge](https://hackmd.io/_uploads/HJe1-wlH0.png =500x)
38> :::
39> 這是 Sanity Check 喔!
40> 直接複製貼上卽可!
41> 找到flag 就是CTF 的精髓啦~
42> `FhCTF{W3cOmE_ch4113nger_e8a898e5be97e58aabe585a5e8999be693ace7a4bee59c98}`
43> 簡單的啦!
44> 三類組的毛病了..都想看實體心臟...
45>
46> Author: CXPh03n1x
47
48#### 題解
49
50無
51
52:::info
53Flag: `FhCTF{W3c0mE_ch4ll3nger_e8a898e5be97e58aa0e585a5e8999be693ace7a4bee59c98}`
54:::
55
56<br /> <br /> <br />
57
58---
59
60### Survey
61
62> :::spoiler 原圖
63> ![Challenge](https://hackmd.io/_uploads/BJN8heOrC.png "500px")
64> :::
65> 就是要來調查一下啦~
66> 請大家要回答喔~
67> 這題值5分
68> https://forms.gle/NzDoAgBEu2gbgN6NA
69>
70> Author: CXPh03n1x
71
72#### 題解
73
74表單填完就有了,或是偷吃步
75
76```bash
77$ curl https://docs.google.com/forms/d/e/1FAIpQLSc12s3nmeR4uoVqQrgHYCxOyO71viqTQKn9WVAdzjogM3Xhig/viewform
78| grep -E 'FhCTF{\S+}'
79```
80
81![image](https://hackmd.io/_uploads/HyCQhgdSR.png "700px")
82
83:::info
84Flag: `FhCTF{G00d_G4m3}`
85:::
86
87<br /> <br /> <br />
88
89---
90
91## FORENSICS
92
93### Hex Dumb Dumb
94
95> :::spoiler 原圖
96> ![Challenge](https://hackmd.io/_uploads/BkBGHeVS0.png "500px")
97> :::
98> 我說,用 UTF-8 已經過時了!現在都用 6865786g6d616c
99> 但是總覺得..你會看不透XD
100>
101> Author: CXPh03n1x
102
103#### 題解
104
105使用`xxd`會發現怪怪的,FhC...,把首行出現的字母組合起來便是Flag
106那個`#`是底線 .w.
107
108:::spoiler content
109
110```
11100040dd0: 0000 4646 4646 4646 0000 0000 0000 0000 ..FFFFFF........
11200040de0: 0000 2929 2929 2929 0000 0000 0000 0000 ..))))))........
11300040df0: 0000 0000 0066 0066 0000 0000 0000 0000 .....f.f........
114# ...
11500040f80: 0000 0000 0000 0029 0000 0000 0000 0000 .......)........
11600040f90: 0000 0000 0000 0074 0000 0000 0000 0000 .......t........
11700040fa0: 0000 5454 5454 5474 0000 0000 0000 0000 ..TTTTTt........
118```
119
120:::
121
122:::info
123Flag: `FhCTF{H3xdump_n33d_m0R3_S3CUR3}`
124:::
125
126<br /> <br /> <br />
127
128---
129
130### Do you know packet?
131
132> :::spoiler 原圖
133> ![Challenge](https://hackmd.io/_uploads/rk27IgNHC.png "500px")
134> :::
135> I receive a PCAP file. But...., what it means?
136>
137> Author: Scott
138
139#### 題解
140
1411. 看到很多USB的封包,猜是要來解並分析內容,先過濾需要被分析的封包
142 `((usb.transfer_type == 0x01) && (frame.len == 35)) && !(usb.capdata == 00:00:00:00:00:00:00:00)`
143 ![image](https://hackmd.io/_uploads/BJ1wEwESC.png)
144
1452. 將 HID Data 導出並使用腳本分析
146
147:::spoiler code
148
149```python=
150BOOT_KEYBOARD_MAP = {
151 0x00: (None, None), # Reserved (no event indicated)
152 0x01: ('', ''), # ErrorRollOver
153 # ...
154 0x73: ('[F24]', '[F24]'), # F24
155}
156
157
158def parse_boot_keyboard_report(data: bytearray):
159 # 數據解析
160 # ...
161
162if __name__ == '__main__':
163 lines = "001af8001a00f8ff,0024f9002400f9ff,0028fa002800faff,0030f9003000f9ff,0034fb003400fbff,0032fa003200faff,002efa002e00faff,002cfb002c00fbff,0023fc002300fcff,001dfb001d00fbff,0016fc001600fcff,000ffe000f00feff,0008fd000800fdff,0004fe000400feff,0000ff000000ffff,0000ff000000ffff,00ff0000ffff0000,0000ff000000ffff,0000ff000000ffff,00ffff00ffffffff,0000ff000000ffff,00ff0000ffff0000,0100000000000000,0000000000000000,0200000000000000,0200090000000000,0200000000000000,0000000000000000,00000b0000000000,0000000000000000,0200000000000000,0200060000000000,0200000000000000,0200170000000000,0200000000000000,0200090000000000,0200000000000000,02002f0000000000,0200000000000000,0000000000000000,0000040000000000,0000000000000000,0200000000000000,02002d0000000000,0200000000000000,0000000000000000,0200000000000000,0200160000000000,0200000000000000,0000000000000000,00001e0000000000,0000000000000000,0000100000000000,0000000000000000,0000130000000000,0000000000000000,00001e0000000000,0000000000000000,0000200000000000,0000000000000000,0200000000000000,02002d0000000000,0200000000000000,0200180000000000,0200000000000000,0200160000000000,0200000000000000,0200050000000000,0200000000000000,0000000000000000,0200000000000000,02002d0000000000,0200000000000000,0200060000000000,0200000000000000,0000000000000000,0200000000000000,02001f0000000000,0200000000000000,0000000000000000,0000130000000000,0000000000000000,0000240000000000,0000000000000000,0000180000000000,0000000000000000,0200000000000000,0200150000000000,0200000000000000,0000000000000000,0000080000000000,0000000000000000,0200000000000000,0200300000000000,0200000000000000,0000000000000000,00fafe00fafffeff,00effa00effffaff,00eefa00eefffaff,00eefa00eefffaff,00ecfa00ecfffaff,00edfc00edfffcff,00effc00effffcff,00f3fc00f3fffcff,00f2fa00f2fffaff,00f3fa00f3fffaff,00f1f900f1fff9ff,00f4fa00f4fffaff,00f3f900f3fff9ff,00f3fb00f3fffbff,00f4fb00f4fffbff,00f6fc00f6fffcff,00f9ff00f9ffffff,00fb0000fbff0000,00fb0000fbff0000,00fb0000fbff0000,00f60000f6ff0000,00f20000f2ff0000,00f10000f1ff0000,00edfe00edfffeff,00ecfd00ecfffdff,00ebfc00ebfffcff,00ecfc00ecfffcff,00edfb00edfffbff,00effc00effffcff,00f0fa00f0fffaff,00f2f900f2fff9ff,00f3fa00f3fffaff,00f7fc00f7fffcff,00f7fb00f7fffbff,00f9fc00f9fffcff,00fbfe00fbfffeff,00fcfe00fcfffeff,00ff0000ffff0000,00fd0000fdff0000,00fe0000feff0000,00fa0300faff0300,00f40400f4ff0400,00f20600f2ff0600,00f10800f1ff0800,00f30900f3ff0900,00f80600f8ff0600,00fa0800faff0800,00fd0100fdff0100,0000010000000100,00fdff00fdffffff,00fffe00fffffeff,00ff0000ffff0000,0002000002000000,0005000005000000,0006ff000600ffff,0006fe000600feff,000cfe000c00feff,000afc000a00fcff,000ffb000f00fbff,0011f9001100f9ff,0015f7001500f7ff,0014fa001400faff,0016f9001600f9ff,0017fb001700fbff,0015fb001500fbff,000ffc000f00fcff,0007fb000700fbff,0003f9000300f9ff,0000fb000000fbff,00fbf900fbfff9ff,00f5f700f5fff7ff,00eff900effff9ff,00ecf800ecfff8ff,00e6f800e6fff8ff,00e0f900e0fff9ff,00d6f800d6fff8ff,00d3f700d3fff7ff,00cff700cffff7ff,00cdf700cdfff7ff,00caf700cafff7ff,00c9f900c9fff9ff,00cdf700cdfff7ff,00d1f800d1fff8ff,00ddf900ddfff9ff,00e7fa00e7fffaff,00f1fa00f1fffaff,00fafa00fafffaff,00fefe00fefffeff,0000ff000000ffff,0000ff000000ffff,0001000001000000,0001000001000000,0001010001000100,0003040003000400,0004050004000500,0004050004000500,0005040005000400,0003030003000300,0004030004000300,0004030004000300,0005030005000300,0006020006000200,0008030008000300,0005010005000100,0005020005000200,0006010006000100,0007020007000200,0009010009000100,0008030008000300,0009020009000200,0007020007000200,0007030007000300,0009020009000200,0007030007000300,000c03000c000300,000a03000a000300,000c04000c000400,000d04000d000400,000a04000a000400,0007020007000200,0005010005000100,0005010005000100,0007020007000200,0005000005000000,0007010007000100,000a01000a000100,000c00000c000000,000d01000d000100,0011010011000100,0010010010000100,000e01000e000100,000c00000c000000,000a00000a000000,0001000001000000,0000020000000200,00ff0000ffff0000,00ff0000ffff0000,0000010000000100,0000010000000100,0001000001000000,0001000001000000,0001000001000000,0002010002000100,0002010002000100,0003020003000200,0002010002000100,0001010001000100,0001010001000100,0001000001000000,0001010001000100,0001000001000000,0001000001000000,0001000001000000,0001000001000000,0001010001000100,0002010002000100,0003010003000100,0002010002000100,0003020003000200,0002010002000100,0002010002000100,0001000001000000,0001000001000000,0001000001000000,0001000001000000,0001000001000000,0000020000000200,0001020001000200,0000020000000200,0001020001000200,0000030000000300,0001020001000200,0000020000000200,0000010000000100,0000030000000300,0000020000000200,0000010000000100,0000010000000100,0001000001000000,0001000001000000,0001010001000100,0100000000000000,0000000000000000".split(',')
164 # ...
165 print(f'Raw output:\n{text.__repr__()}')
166 print(f'Text output:\n{text}')
167
168
169>>>
170"""
171Raw output:
172"w7\n]'= 6zsleaFhCTF{a_S1mp13_USB_C@p7uRe}aacceeffcceebcciglnrqstrldaababbababaaabcebbcdfefddfdigaiaajaagadbbdbdgijnmkig"
173Text output:
174w7
175]'= 6zsleaFhCTF{a_S1mp13_USB_C@p7uRe}aacceeffcceebcciglnrqstrldaababbababaaabcebbcdfefddfdigaiaajaagadbbdbdgijnmkig
176"""
177```
178
179:::
180
181:::info
182Flag: `FhCTF{a_S1mp13_USB_C@p7uRe}`
183:::
184
185<!-- Hackmd Only -->
186
187---
188
189> [name=salt]\
190> [name=鄭] \
191> [name=XinShou]\
192> [name=wasami]
193
194---
195
196<style>
197 .markdown-body p {
198 font-size: 18px;
199 }
200</style>
201
202<!-- /Hackmd Only -->
腳本
1#!/usr/bin/env python3
2# 將 Hackmd 中的筆記內容轉為 Gokarna 相容的顯示樣式
3# Usage: ./Hackmd2blog.py ./target.md ./output.md
4# Author: XinShou
5
6import sys
7import re
8
9
10class Hackmd2blog:
11 file_path: str
12 content: str = None
13
14 def __init__(self, file_path):
15 self.file_path = file_path
16 self.read_file()
17 self.remove_hackmd_only_sections()
18 self.remove_placeholder()
19 self.convert_flag_info_spoiler()
20 self.convert_spoiler()
21 self.convert_code_block()
22 self.convert_image_size_format()
23 self.content = self.content.strip()
24
25 # def parseTitle(self):
26 # extracted_text = re.search(r'^---(.*?)---', self.content, re.DOTALL)
27 # if not extracted_text:
28 # raise RuntimeError
29 #
30 # extracted_text = extracted_text.group(1).strip()
31 # return extracted_text
32 def read_file(self):
33 with open(self.file_path, 'r') as f:
34 self.content = f.read().strip()
35
36 def remove_hackmd_only_sections(self):
37 """
38 Removes sections marked explicitly for Hackmd Only from the provided text.
39 """
40 self.content = re.sub(r'<!-- Hackmd Only -->.*?<!-- /Hackmd Only -->', '', self.content, flags=re.DOTALL)
41
42 def convert_spoiler(self):
43 """
44 Converts Hackmd spoiler syntax to Hugo spoiler shortcode syntax.
45 """
46 converted_text = re.sub(r':::spoiler (.*)\n', r'
\1
\n’, self.content)
converted_text = re.sub(r’:::\n’, r'
\n', converted_text)
47 self.content = converted_text
48
49 def convert_flag_info_spoiler(self):
50 """
51 Converts Hackmd info block to Markdown blockquote.
52 """
53 self.content = re.sub(r':::info\n(.*)\n:::', r'> \1', self.content)
54
55 def convert_code_block(self):
56 """
57 Converts standard Markdown code blocks to code blocks with inline line numbers.
58 """
59 self.content = re.sub(r'```([a-z]+)=', r'```\1 {linenos=inline}', self.content)
60
61 def remove_placeholder(self):
62 self.content = self.content.replace('<br />', '')
63
64 def convert_image_size_format(self):
65 """
66 Converts Markdown image links from size format '=500x' to ' "500px"'.
67 """
68 self.content = re.sub(r'\(https://hackmd.io/_uploads/([^ ]+) =(\d+)x\)',
69 r'(https://hackmd.io/_uploads/\1 "\2px")', self.content)
70
71
72if __name__ == '__main__':
73 if len(sys.argv) != 3:
74 print("Usage: ./hackmd2blog target.md output.md")
75 sys.exit(1)
76
77 input_file = sys.argv[1]
78 output_file = sys.argv[2]
79
80 h2b = Hackmd2blog(input_file)
81 with open(output_file, 'w') as f:
82 f.write(h2b.content)