Skip to content

Commit 475ce38

Browse files
author
gsbp
committed
update
1 parent e27783f commit 475ce38

File tree

15 files changed

+422
-218
lines changed

15 files changed

+422
-218
lines changed

content/post/d3ctf2025.md

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,183 @@ download_file("flag", "downloaded_example.txt")
384384

385385
## tidy quic
386386

387-
在写了在写了
387+
这题考的是http3协议
388+
389+
先分析题目
390+
391+
```
392+
package main
393+
394+
import (
395+
"bytes"
396+
"errors"
397+
"github.com/libp2p/go-buffer-pool"
398+
"github.com/quic-go/quic-go/http3"
399+
"io"
400+
"log"
401+
"net/http"
402+
)
403+
404+
var p pool.BufferPool
405+
var ErrWAF = errors.New("WAF")
406+
407+
func main() {
408+
go func() {
409+
err := http.ListenAndServeTLS(":8088", "./server.crt", "./server.key", &mux{})
410+
log.Fatalln(err)
411+
}()
412+
go func() {
413+
err := http3.ListenAndServeQUIC(":8088", "./server.crt", "./server.key", &mux{})
414+
log.Fatalln(err)
415+
}()
416+
select {}
417+
}
418+
419+
type mux struct {
420+
}
421+
422+
func (*mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
423+
if r.Method == http.MethodGet {
424+
_, _ = w.Write([]byte("Hello D^3CTF 2025,I'm tidy quic in web."))
425+
return
426+
}
427+
if r.Method != http.MethodPost {
428+
w.WriteHeader(400)
429+
return
430+
}
431+
432+
var buf []byte
433+
length := int(r.ContentLength)
434+
if length == -1 {
435+
var err error
436+
buf, err = io.ReadAll(textInterrupterWrap(r.Body))
437+
if err != nil {
438+
if errors.Is(err, ErrWAF) {
439+
w.WriteHeader(400)
440+
_, _ = w.Write([]byte("WAF"))
441+
} else {
442+
w.WriteHeader(500)
443+
_, _ = w.Write([]byte("error"))
444+
}
445+
return
446+
}
447+
} else {
448+
buf = p.Get(length)
449+
defer p.Put(buf)
450+
rd := textInterrupterWrap(r.Body)
451+
i := 0
452+
for {
453+
n, err := rd.Read(buf[i:])
454+
if err != nil {
455+
if errors.Is(err, io.EOF) {
456+
break
457+
} else if errors.Is(err, ErrWAF) {
458+
w.WriteHeader(400)
459+
_, _ = w.Write([]byte("WAF"))
460+
return
461+
} else {
462+
w.WriteHeader(500)
463+
_, _ = w.Write([]byte("error"))
464+
return
465+
}
466+
}
467+
i += n
468+
}
469+
}
470+
if !bytes.HasPrefix(buf, []byte("I want")) {
471+
_, _ = w.Write([]byte("Sorry I'm not clear what you want."))
472+
return
473+
}
474+
item := bytes.TrimSpace(bytes.TrimPrefix(buf, []byte("I want")))
475+
if bytes.Equal(item, []byte("flag")) {
476+
_, _ = w.Write([]byte("flfag{test}"))
477+
} else {
478+
_, _ = w.Write(item)
479+
}
480+
}
481+
482+
type wrap struct {
483+
io.ReadCloser
484+
ban []byte
485+
idx int
486+
}
487+
488+
func (w *wrap) Read(p []byte) (int, error) {
489+
n, err := w.ReadCloser.Read(p)
490+
if err != nil && !errors.Is(err, io.EOF) {
491+
return n, err
492+
}
493+
for i := 0; i < n; i++ {
494+
if p[i] == w.ban[w.idx] {
495+
w.idx++
496+
if w.idx == len(w.ban) {
497+
return n, ErrWAF
498+
}
499+
} else {
500+
w.idx = 0
501+
}
502+
}
503+
return n, err
504+
}
505+
506+
func textInterrupterWrap(rc io.ReadCloser) io.ReadCloser {
507+
return &wrap{
508+
rc, []byte("flag"), 0,
509+
}
510+
}
511+
```
512+
513+
我们在go中的题目主要要关注的点就是在于题目中的全局变量,这差不多是经验之谈了hh
514+
515+
所以我们可以看到题目中的`var p pool.BufferPool`,一个缓冲池
516+
517+
在http通信中,如果`Content-Length!=-1`(即没写CL头),则不会调用缓冲区来读取数据,反之则会使用
518+
519+
```
520+
buf = p.Get(length)
521+
defer p.Put(buf)
522+
```
523+
524+
这里主要在于`defer p.Put(buf)`,观察代码上下文也没有对已经写入了body数据的buf缓冲区进行重置清零的操作,而是直接将她放回的缓冲池,这就会导致缓冲池会出现一个被污染的状态,下一次从缓冲池中取出缓冲区也会受到这些数据的影响
525+
526+
第一次
527+
528+
![image-20250602150550525](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602150550525.png)
529+
530+
第二次
531+
532+
![image-20250602150620439](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602150620439.png)
533+
534+
所以我们现在的想法就是,让上次的buf影响到下次的结果
535+
536+
我们可以让第一次的数据为a bcde flag 第二次的为i want,这样在被污染过后就会成为i want flag,注意这里两次的请求的Content-Length都要为11,即使第二次只post了6个数据,否则取不到对应长度的buf
537+
538+
接下来的操作体现了http3和http2的区别
539+
540+
http2
541+
542+
省略了前面post i want flag的一步
543+
544+
![image-20250602151342432](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151342432.png)
545+
546+
![image-20250602151408560](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151408560.png)
547+
548+
结果在读取我们post的10个数据之后,读取行为并没结束,http2还在等待剩下的一位继续输入而并没有发送eof结束
549+
550+
![image-20250602151504499](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151504499.png)
551+
552+
http3
553+
554+
![image-20250602151644729](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151644729.png)
555+
556+
结果http3在一次读取之后就到了eof结束的地方
557+
558+
![image-20250602151732504](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151732504.png)
559+
560+
![image-20250602151855662](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602151855662.png)
561+
562+
563+
564+
这里体现出来http2和http3的区别:http2在Content-Length比body实际长度大时,会等待一会儿的输入,来使两者相等,而http3则会更精准的检测出body的实际长度并且在body发送完毕之后迅速的发送结束流,也可以说是quic不会根据http请求包中的Content-Length来界定body的结束
565+
566+
![image-20250602152322273](https://tuchuang-1322176132.cos.ap-chengdu.myqcloud.com//imgimage-20250602152322273.png)

public/categories/index.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
<description>Recent content in Categories on GSBP&#39;s Blog</description>
77
<generator>Hugo</generator>
88
<language>en-us</language>
9-
<lastBuildDate>Thu, 15 May 2025 16:57:31 +0800</lastBuildDate>
9+
<lastBuildDate>Sun, 01 Jun 2025 21:00:00 +0800</lastBuildDate>
1010
<atom:link href="http://localhost:1313/categories/index.xml" rel="self" type="application/rss+xml" />
11+
<item>
12+
<title>Java安全</title>
13+
<link>http://localhost:1313/categories/java%E5%AE%89%E5%85%A8/</link>
14+
<pubDate>Sun, 01 Jun 2025 21:00:00 +0800</pubDate>
15+
<guid>http://localhost:1313/categories/java%E5%AE%89%E5%85%A8/</guid>
16+
<description></description>
17+
</item>
1118
<item>
1219
<title>WP</title>
1320
<link>http://localhost:1313/categories/wp/</link>
14-
<pubDate>Thu, 15 May 2025 16:57:31 +0800</pubDate>
21+
<pubDate>Sun, 01 Jun 2025 21:00:00 +0800</pubDate>
1522
<guid>http://localhost:1313/categories/wp/</guid>
1623
<description></description>
1724
</item>
@@ -22,13 +29,6 @@
2229
<guid>http://localhost:1313/categories/%E4%BA%91%E5%AE%89%E5%85%A8/</guid>
2330
<description></description>
2431
</item>
25-
<item>
26-
<title>Java安全</title>
27-
<link>http://localhost:1313/categories/java%E5%AE%89%E5%85%A8/</link>
28-
<pubDate>Mon, 24 Mar 2025 22:00:00 +0800</pubDate>
29-
<guid>http://localhost:1313/categories/java%E5%AE%89%E5%85%A8/</guid>
30-
<description></description>
31-
</item>
3232
<item>
3333
<title>CVE</title>
3434
<link>http://localhost:1313/categories/cve/</link>

public/categories/java安全/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,49 +146,49 @@ <h2 class="archive-title">Category: Java安全</h2>
146146

147147

148148
<article class="archive-item">
149-
<a href="http://localhost:1313/post/%E8%BD%AF%E4%BB%B6%E6%94%BB%E9%98%B2%E8%B5%9B%E7%8E%B0%E5%9C%BA%E8%B5%9B%E4%B8%8A%E5%AF%B9justdeserialize%E6%94%BB%E5%87%BB%E7%9A%84%E5%87%A0%E6%AC%A1%E5%B0%9D%E8%AF%95/" class="archive-item-link hover-underline-animation">软件攻防赛现场赛上对justDeserialize攻击的几次尝试</a>
149+
<a href="http://localhost:1313/post/d3ctf2025/" class="archive-item-link hover-underline-animation">D3CTF 2025-WP</a>
150150
<span class="archive-item-date">
151-
March 24, 2025
151+
June 1, 2025
152152
</span>
153153

154154
</article>
155155

156156

157157

158158
<article class="archive-item">
159-
<a href="http://localhost:1313/post/tomcatcve-2025-24813%E5%A4%8D%E7%8E%B0%E5%8F%8A%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90/" class="archive-item-link hover-underline-animation">[Tomcat]CVE-2025-24813复现及原理分析</a>
159+
<a href="http://localhost:1313/post/%E8%BD%AF%E4%BB%B6%E6%94%BB%E9%98%B2%E8%B5%9B%E7%8E%B0%E5%9C%BA%E8%B5%9B%E4%B8%8A%E5%AF%B9justdeserialize%E6%94%BB%E5%87%BB%E7%9A%84%E5%87%A0%E6%AC%A1%E5%B0%9D%E8%AF%95/" class="archive-item-link hover-underline-animation">软件攻防赛现场赛上对justDeserialize攻击的几次尝试</a>
160160
<span class="archive-item-date">
161-
March 12, 2025
161+
March 24, 2025
162162
</span>
163163

164164
</article>
165165

166166

167167

168168
<article class="archive-item">
169-
<a href="http://localhost:1313/post/springaop/" class="archive-item-link hover-underline-animation">SpringAOP链学习</a>
169+
<a href="http://localhost:1313/post/tomcatcve-2025-24813%E5%A4%8D%E7%8E%B0%E5%8F%8A%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90/" class="archive-item-link hover-underline-animation">[Tomcat]CVE-2025-24813复现及原理分析</a>
170170
<span class="archive-item-date">
171-
January 23, 2025
171+
March 12, 2025
172172
</span>
173173

174174
</article>
175175

176176

177177

178178
<article class="archive-item">
179-
<a href="http://localhost:1313/post/jdk17%E6%89%93jackson&#43;ldapattruibute%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96/" class="archive-item-link hover-underline-animation">JDK17打Jackson&#43;LdapAttruibute反序列化</a>
179+
<a href="http://localhost:1313/post/springaop/" class="archive-item-link hover-underline-animation">SpringAOP链学习</a>
180180
<span class="archive-item-date">
181-
January 20, 2025
181+
January 23, 2025
182182
</span>
183183

184184
</article>
185185

186186

187187

188188
<article class="archive-item">
189-
<a href="http://localhost:1313/post/d3ctf2025/" class="archive-item-link hover-underline-animation">D3CTF 2025-WP</a>
189+
<a href="http://localhost:1313/post/jdk17%E6%89%93jackson&#43;ldapattruibute%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96/" class="archive-item-link hover-underline-animation">JDK17打Jackson&#43;LdapAttruibute反序列化</a>
190190
<span class="archive-item-date">
191-
January 1, 0001
191+
January 20, 2025
192192
</span>
193193

194194
</article>

0 commit comments

Comments
 (0)