URL中的各部分参数 - http身份认证
# URL中的各部分参数
CTF web手应该会都做过这个考点的题目,示例http://domain@2130706433
,@
符用来分隔userinfo
、host
,访问这个url可以直接把用户名、密码的参数值传给@
后面要访问的主机,可以打一个重定向或者SSRF
url的各部分
<scheme>://<userinfo>@<host>:<port>/<path>?<query>#<fragment>
1
scheme:协议(如
http
、https
)userinfo:可选的“用户名:密码”信息,用于 HTTP 认证
host:域名或 IP 地址
@:“@”符号,用来分隔参数
userinfo
和要访问的host
port:端口(可省略,则默认 80 或 443)
path、query、fragment:资源路径、查询参数和锚点
一直没有一个直接的机会了解@
前的userinfo
这部分倒带是什么,今天终于碰到了,记录一下
对于这个http认证,有多种方式进行认证,可以手动输入,也可以使用curl命令,或者hackerbar、bp里使用Authorization头进行认证。
curl -u username:password http://example.com
curl --user username:password http://example.com
curl -H "Authorization: Basic YWRtaW46MTIzNDU2" http://example.com
curl http://username:password@example.com
1
2
3
4
2
3
4
在这条命令里,curl使用-H
参数添加了一个HTTP头部,Authorization头部的值为Basic + base64编码后的用户名:密码(admin:123456)。
curl -H "Authorization: Basic YWRtaW46MTIzNDU2" http://example.com
1
类似http://admin@domain.com/
的url,使用用户名为admin
,密码为空的参数访问主机domain.com
。
对于没有开启http认证的服务器,即使添加userinfo
部分,服务器不会处理解释这个部分,相当于直接忽略掉了,直接访问后面的主机部分。
# nginx配置http认证
使用nginx配置http认证,复现:
准备以下3个文件
- nginx.conf
- dockerfile
- docker-compose.yml
1
2
3
2
3
nginx.conf
events {}
http {
server {
listen 80;
server_name _;
# 开启 Basic Auth
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
root /var/www/html;
index index.html;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
dockerfile
FROM nginx:latest
# 安装 htpasswd 并生成账号 admin:123456
RUN apt-get update \
&& apt-get install -y apache2-utils \
&& htpasswd -cb /etc/nginx/.htpasswd admin 123456 \
&& rm -rf /var/lib/apt/lists/*
RUN mkdir -p /var/www/html \
&& echo '<!DOCTYPE html><html><body>Hello, admin!</body></html>' \
> /var/www/html/index.html
COPY nginx.conf /etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
docker-compose.yml
version: '3.8'
services:
nginx-auth:
# 从本目录的 Dockerfile 构建镜像
build:
context: .
dockerfile: Dockerfile
container_name: nginx-auth-demo
ports:
- "8080:80"
restart: unless-stopped
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
启动环境
docker compose up -d --build
1
关闭环境
docker compose down
1
编辑 (opens new window)
最后一次更新于: 2025/04/29, 01:26:37