关于parse_url()函数 作者: ynnddddd 时间: 2024-08-18 分类: 网络安全,RCE,函数漏洞 1.parse_url()语法 --------------- parse_url ( string $url [, int $component = -1 ] ) #参数 结果: Array ( [scheme] => http [host] => host [user] => user [pass] => pass [path] => /path [query] => args=value [fragment] => anch ) 2.parse_url() 的分割规则 ----------------- parse_url() 函数按照以下顺序和规则解析 URL: Scheme: parse_url() 首先寻找 ://,以此分割出协议部分(即 scheme)。 例如,https://example.com 中的 https 被识别为 scheme。 User Info: 如果 URL 包含用户信息(user:pass@),parse_url() 会在 @ 前查找是否存在 :,以此分割出 user 和 pass。如果没有密码部分,那么整个 @ 前的内容会被解析为 user。 例如,https://user:pass@example.com 中 user:pass 被识别为 user 和 pass。 Host: 在 :// 后,直到遇到第一个 /、: 或者 ? 之前的部分被解析为 host。 例如,https://example.com:8080 中 example.com 被识别为 host。 Port: 如果 host 后面紧跟着 :port,parse_url() 会将 : 后的数字解析为 port。 例如,https://example.com:8080 中的 8080 被识别为 port。 Path: 在 host 和 port 之后,遇到第一个 ? 或 # 之前的部分被解析为 path。 例如,https://example.com/path/to/resource 中的 /path/to/resource 被识别为 path。 Query: 如果 URL 包含 ?,从 ? 开始直到 # 或字符串末尾的部分被解析为 query。 例如,https://example.com/path?name=John 中的 name=John 被识别为 query。 Fragment: 如果 URL 包含 #,从 # 开始直到字符串末尾的部分被解析为 fragment。 例如,https://example.com/path#section2 中的 section2 被识别为 fragment。 以下面例子 https://user:pass@www.example.com:8080/path/to/resource?name=John&age=25#section2 parse_url() 会按照以下顺序进行解析: Scheme: 识别 https。 User Info: 识别 user 和 pass。 Host: 识别 www.example.com。 Port: 识别 8080。 Path: 识别 /path/to/resource。 Query: 识别 name=John&age=25。 Fragment: 识别 section2。 最终,parse_url() 返回一个包含上述各部分的数组。 3.常规绕过方法(待补充) -------- 1. 对于高版本的php的来说 直接/// 三个斜杠导致 严重不合格的 URL,parse_url() 返回FALSE 这个是通用的绕过方法. 2. parse_url()会把//认为是相对路径**(5.4.7以前)**也就是说 http://127.0.0.1//path?googleguy=googley 这里识别出来的host不是127.0.0.1,而是//path? 而googleguy=googley就成为了path而不是query了 3. ..... [博客套用][1] [1]: https://blog.csdn.net/Elite__zhb/article/details/130095325 标签: parse_url, 绕过.