{"id":43705936,"url":"https://github.com/cokeBeer/go-sec-code","last_synced_at":"2026-02-16T16:00:41.498Z","repository":{"id":38690008,"uuid":"479923924","full_name":"cokeBeer/go-sec-code","owner":"cokeBeer","description":"Go-sec-code is a  project for learning Go vulnerability code.","archived":false,"fork":false,"pushed_at":"2023-03-11T14:28:39.000Z","size":664,"stargazers_count":37,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T07:43:02.597Z","etag":null,"topics":["cors","go","jsonp","security","sqli","ssrf","ssti","xss","xxe"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cokeBeer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-10T05:38:57.000Z","updated_at":"2025-03-11T12:49:07.000Z","dependencies_parsed_at":"2023-01-21T22:48:03.524Z","dependency_job_id":null,"html_url":"https://github.com/cokeBeer/go-sec-code","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cokeBeer/go-sec-code","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cokeBeer%2Fgo-sec-code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cokeBeer%2Fgo-sec-code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cokeBeer%2Fgo-sec-code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cokeBeer%2Fgo-sec-code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cokeBeer","download_url":"https://codeload.github.com/cokeBeer/go-sec-code/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cokeBeer%2Fgo-sec-code/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29512225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cors","go","jsonp","security","sqli","ssrf","ssti","xss","xxe"],"created_at":"2026-02-05T06:00:17.293Z","updated_at":"2026-02-16T16:00:41.490Z","avatar_url":"https://github.com/cokeBeer.png","language":"Go","funding_links":[],"categories":["Web安全"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eWelcome to go-sec-code 👋\u003c/h1\u003e\n\u003cp\u003e\n\u003c/p\u003e\n\n\u003e Go-sec-code is a  project for learning Go vulnerability code.\n\n### 🏠 [Homepage](https://github.com/cokeBeer/go-sec-code)\n- [Introduction](#introduction)\n- [Install](#install)\n- [漏洞说明](#漏洞说明)\n  - [SSTI](#ssti)\n  - [XXE](#xxe)\n  - [SSRF](#ssrf)\n  - [Path Traversal](#path-traversal)\n## Introduction\n\n用beego作为后端框架开发的go语言靶场，目前已经完成\n\n- CommandInjection\n  - GET参数注入\n  - Host头注入\n  - git参数注入\n  - 安全代码\n- Cors\n  - 反射型Cors\n  -  any-origin-with-credential\n  - 安全代码\n- CRLFInjection\n  - 安全代码\n- FileUpload\n  - 利用POST参数任意目录写文件\n  - 安全代码\n- JSONP\n  - 无防护\n  - 空Referer绕过\n  - 安全代码\n- PathTraversal\n  - 无防护\n  - 错误使用Clean()\n  - 安全代码（过滤）\n  - 安全代码（前缀检查）\n- SQLInjection\n  - 数字型注入\n  - 字符型注入\n  - 错误的ORM使用\n  - 错误的SQL生成器使用\n  - 数字型安全代码\n  - 字符型安全代码\n  - ORM安全代码\n- SSRF\n  - 无防护\n  - 混淆绕过\n  - 302绕过\n  - 安全代码（白名单）\n- SSTI\n  - 漏洞代码\n  - 安全代码\n- XSS\n  - 反射型xss\n  - 存储型xss\n  - SVG型xss\n  - PDF型xss\n  - 基于过滤的修复\n  - 基于CSP的修复\n- XXE\n  - 漏洞代码\n  - 安全代码\n- ZipSlip\n  - 漏洞代码\n\n\n\n## Install\n\n运行需要安装beego和bee\n\n参考:[beego和bee安装](https://github.com/beego/beedoc/blob/master/zh-CN/quickstart.md)\n\n然后执行\n\n```\ngit clone https://github.com/cokeBeer/go-sec-code\ncd go-sec-code\nbee run\n```\n\n服务器就运行在http://localhost:233 上了\n\n![](go-sec-code.png)\n\n为了测试SQLInjection，需要连接数据库。这里使用mysql，先执行下面的语句创建数据库和表\n\n```sql\ncreate database goseccode;\ncreate table user(\n\tid int,\n\tusername varchar(40),\n\tpassword varchar(40),\n);\ninsert into user values(1,\"admin\",\"admin@123\");\ninsert into user values(2,\"test\",\"test@123\");\n```\n\n然后找到sqlinjection.go，修改source变量的值\n\n```go\nsource := \"username:password@tcp(127.0.0.1:3306)/goseccode\"\n```\n\n即可连接数据库\n## 漏洞说明\n\n### SSTI\ngo语言本身提供的模版引擎仅支持简单的渲染功能，不像php、java、python 的模版引擎支持多种功能。这里在设计漏洞代码的时候找到了一个go 语言模版引擎常用的增强库[sprig](https://github.com/Masterminds/sprig)，有2.9k个star。这个增强库提供了一些常用的模版函数，其中`env`这个方法可以用来读取环境变量，能造成信息泄露。其他函数经检查，都较为安全。\n\n### XXE\n\ngo语言本身提供的xml解析库直接忽略了xml文档中的entity和dtd标签。这里在设计漏洞代码的时候找到了一个go语言实现的libxml2库[libxml2](https://github.com/lestrrat-go/libxml2)，有193个star。这个增强库可以设置支持entity。其他go语言实现的xml库大多不支持entity和dtd标签，或者是直接封装了go语言本身提供的xml库。\n\n### SSRF\n\nSSRF提供了三种漏洞情形，一种安全情形。其中第二种漏洞情形用来表示黑名单不完善的情况，第三种漏洞情形来表示黑名单较为完善的情况。黑名单一般要用到字符串比较函数来实现。go语言中进行字符串比较的函数主要是`strings.HasSuffix`。这个函数在比较时不考虑大小写，如果直接使用这个函数进行比较，会导致大小写绕过。更安全的写法是使用`strings.ToLower`先将域名统一转换为小写再进行比较。\n\n### Path Traversal\n\ngo语言提供了`filepath.Clean()`方法来规范化路径。但是这个方法不会规范没有以`/`开头的相对路径，例如`../../secret`。简单地使用`filepath.Clean()`方法来规范化路径会导致路径变遍历。比较安全的写法是使用`filepath.Join()`将指定目录（例如`static/`）与传入的参数进行拼接，然后使用`strings.HasPrefix()`方法来检查是否发生了目录穿越","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcokeBeer%2Fgo-sec-code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FcokeBeer%2Fgo-sec-code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FcokeBeer%2Fgo-sec-code/lists"}