RedTeaming RedTeaming
首页
🤡Blog
🍓Marshal
  • 分类
  • 标签
  • 归档
GitHub

Wing

Less talk,More work!
首页
🤡Blog
🍓Marshal
  • 分类
  • 标签
  • 归档
GitHub
  • 安全开发

    • 基于Gin框架隐藏Web系统登录页面
      • 背景
      • 实现
    • SourceMap反编译工具
    • 调用阿里云OpenAPI创建抢占式实例
  • 渗透测试

  • 二进制安全

  • BypassAV

  • 漏洞利用

  • 内网渗透

  • Blog
  • 安全开发
Wing
2023-06-11

基于Gin框架隐藏Web系统登录页面

# 背景

我不太想泄露系统的Web登录页面,所以针对静态资源和根路径的请求我准备加一个401认证。

# 实现

后端框架是Gin,采用白名单方式,api接口走jwt认证,静态资源和根路径走basic认证。

func BasicAuth(c *gin.Context) (err error) {
	if !strings.Contains(c.Request.URL.Path, "v1/") {
		// 获取 BasicAuth 认证信息
		username, password, ok := c.Request.BasicAuth()
		if !ok {
			c.Header("WWW-Authenticate", "Basic realm=Restricted")
			c.JSON(
				http.StatusUnauthorized,
				gin.H{
					"code": http.StatusUnauthorized,
				})
			return errors.New("用户未登录")
		}

		if config.Cfg.Web.BasicAuth.Username == username && config.Cfg.Web.BasicAuth.Password == password {
			c.Next()
			return
		} else {
			c.Header("WWW-Authenticate", "Basic realm=Restricted")
			c.JSON(
				http.StatusUnauthorized,
				gin.H{
					"code": http.StatusUnauthorized,
				})
			return errors.New("用户未登录")
		}
	}
	return nil
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

通过验证后再显示前端即可。

Edit this page
SourceMap反编译工具

SourceMap反编译工具→

最近更新
01
Yakit实战:快速挖掘前后端分离网站的API接口漏洞
07-28
02
调用阿里云OpenAPI创建抢占式实例
06-29
03
Github项目集成qodana进行静态代码扫描
06-26
更多文章>

Wing已运营本站:

本站总访问量 次 | 本站访客数 人
RedTeaming | Copyright © 2020-2024 Wing | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×