当前位置: 首页 > news >正文

公司的网站怎么运营seo短视频网页入口

公司的网站怎么运营,seo短视频网页入口,网站投放广告怎么做,web静态网页设计报告未经许可,不得转载。 文章目录 SSRF漏洞成因Java中发送HTTP请求的函数1、HttpURLConnection2、HttpClient(Java 11)3、第三方库Request库漏洞示例OkHttpClient漏洞示例HttpClients漏洞示例 漏洞代码示例防范标准代码 SSRF SSRF(S…

未经许可,不得转载。

文章目录

    • SSRF
    • 漏洞成因
    • Java中发送HTTP请求的函数
      • 1、HttpURLConnection
      • 2、HttpClient(Java 11+)
      • 3、第三方库
        • Request库漏洞示例
        • OkHttpClient漏洞示例
        • HttpClients漏洞示例
    • 漏洞代码示例
    • 防范
    • 标准代码

在这里插入图片描述

SSRF

SSRF(Server-Side Request Forgery,服务器端请求伪造) 是一种安全漏洞,攻击者可以利用该漏洞诱使服务器向内部或外部的任意系统发起请求。通过SSRF,攻击者可以绕过防火墙或访问限制,访问内部资源,甚至攻击内网中的其他服务。

常见的攻击场景包括:
1、访问内网中的敏感数据。
2、扫描内网端口和服务。
3、利用服务器作为跳板攻击其他系统。
4、访问云服务元数据(如AWS的元数据服务)。

漏洞成因

SSRF漏洞通常是由于应用程序在处理用户输入的URL时,未对其进行严格的验证和过滤,导致攻击者可以构造恶意URL,使服务器发起非预期的请求。

Java中发送HTTP请求的函数

在Java中,发送HTTP请求的常见方式有以下几种。

1、HttpURLConnection

这是Java标准库中的类,用于发送HTTP请求,示例代码如下:

import java.net.HttpURLConnection;  // 导入HttpURLConnection类
import java.net.URL;  // 导入URL类
import java.io.BufferedReader;  // 导入BufferedReader类
import java.io.InputStreamReader;  // 导入InputStreamReader类public class HttpExample {public static void main(String[] args) {try {// 创建URL对象并指定要访问的地址URL url = new URL("https://example.com");// 打开与目标URL的连接HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 设置请求方法为GETconn.setRequestMethod("GET");// 创建BufferedReader读取响应内容BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String inputLine;StringBuilder content = new StringBuilder();// 逐行读取响应并拼接while ((inputLine = in.readLine()) != null) {content.append(inputLine);}// 关闭输入流in.close();// 断开连接conn.disconnect();// 打印网页内容System.out.println(content.toString());} catch (Exception e) {e.printStackTrace();  // 捕获异常并打印错误信息}}
}

2、HttpClient(Java 11+)

Java 11引入的新的HTTP客户端API,功能更强大。

3、第三方库

如Apache HttpClient、OkHttp等。

Request库漏洞示例
String url = request.getParameter("url"); // 从用户输入中获取URL
return Request.Get(url).execute().returnContent().toString(); // 直接使用用户输入的URL发起请求

代码直接从用户输入中获取URL,未进行任何验证或过滤。

OkHttpClient漏洞示例
String url = request.getParameter("url"); // 从用户输入中获取URL
OkHttpClient client = new OkHttpClient();
com.squareup.okhttp.Request ok_http = new com.squareup.okhttp.Request.Builder().url(url).build();
client.newCall(ok_http).execute();  // 使用用户输入的URL发起请求

代码直接使用用户输入的URL构造请求,未对URL进行合法性检查。

HttpClients漏洞示例
String url = request.getParameter("url"); // 从用户输入中获取URL
CloseableHttpClient client = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = client.execute(httpGet); // 使用用户输入的URL发起请求

代码未对用户输入的URL进行任何验证或限制,直接用于发起HTTP请求。

漏洞代码示例

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import javax.servlet.http.HttpServletRequest;public class SSRFExample {public static void main(String[] args) {HttpServletRequest request = getRequest();// 获取请求中的 URL 参数String userInput = request.getParameter("url");if (userInput == null || userInput.isEmpty()) {System.out.println("Please provide a URL as a parameter.");return;}try {// 创建URL对象URL url = new URL(userInput);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET"); //GET方法请求// 读取响应内容BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));String inputLine;StringBuilder content = new StringBuilder();while ((inputLine = in.readLine()) != null) {content.append(inputLine);}in.close();conn.disconnect();// 打印响应内容System.out.println(content.toString());} catch (Exception e) {e.printStackTrace();  // 捕获异常并打印错误信息}}
}

在这个示例中,用户输入的URL直接用于发起HTTP请求,如果攻击者输入一个指向内网服务的URL(如http://169.254.169.254/latest/meta-data/),服务器会访问到敏感的内部资源并返回给客户端。

防范

1、严格验证用户输入的 URL,确保其符合预期格式和范围。

2、合理处理 302 跳转,对跳转地址进行校验,而非直接禁止。

3、限制协议类型,仅允许 http/https,禁止跨协议访问。

4、采用白名单机制,仅允许访问特定域名或 IP 地址:

  • 准确识别内网 IP,并正确解析 Host 头信息。
  • 禁止访问内网 IP 地址及私有 IP 段(如 127.0.0.1、192.168.x.x、10.x.x.x 等)。
  • 拒绝访问敏感 URL(如云服务元数据地址)。

5、配置 Web 端口白名单,防止端口扫描(可能对业务有一定限制)。

标准代码

private static final int CONNECT_TIMEOUT = 5000; // 连接超时时间(毫秒)public static boolean checkSsrf(String url) {HttpURLConnection connection;String finalUrl = url;try {do {// 仅允许 http/https 协议,防止跨协议攻击if (!Pattern.matches("^https?://.+$", finalUrl)) {return false;}// 判断是否为内网 IP,避免 SSRF 访问内部服务if (isInnerIp(finalUrl)) {return false;}// 发起 HTTP 请求,不跟随跳转connection = (HttpURLConnection) new URL(finalUrl).openConnection();connection.setInstanceFollowRedirects(false); // 禁止自动跳转connection.setUseCaches(false); // 禁用缓存,确保每次请求都重新解析 DNSconnection.setConnectTimeout(CONNECT_TIMEOUT); // 设置超时时间,防止长时间阻塞connection.connect(); // 触发 DNS 解析,尝试建立连接int statusCode = connection.getResponseCode();// 检查 3xx 状态码(重定向),但排除 304(缓存)和 306(保留未使用)if (statusCode >= 300 && statusCode <= 307 && statusCode != 304 && statusCode != 306) {String redirectedUrl = connection.getHeaderField("Location");if (redirectedUrl == null) {break; // 若无重定向地址,则终止检查}finalUrl = redirectedUrl; // 继续检查跳转后的 URL} else {break; // 结束循环,URL 无需进一步检查}} while (connection.getResponseCode() != HttpURLConnection.HTTP_OK); // 仅当返回 200 时才终止检查connection.disconnect();} catch (Exception e) {return true; // 捕获异常,返回 true(默认安全策略)}return true;
}private static boolean isInnerIp(String url) throws URISyntaxException, UnknownHostException {URI uri = new URI(url);String host = uri.getHost(); // 提取 Host 部分// 解析 Host 对应的 IP 地址,并标准化为 IPv4 格式InetAddress inetAddress = InetAddress.getByName(host);String ip = inetAddress.getHostAddress();// 定义内网 IP 段(私有地址范围)String[] privateSubnets = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8"};for (String subnet : privateSubnets) {SubnetUtils subnetUtils = new SubnetUtils(subnet); // 使用 commons-net 进行子网匹配if (subnetUtils.getInfo().isInRange(ip)) {return true; // IP 属于内网地址范围,返回 true}}return false;
}

说明:
1、return false → 发现安全问题时(如协议不合法、检测到内网 IP),返回 false,表示 URL 不安全。
2、return true → 没有发现明确安全问题,返回 true,允许执行。


文章转载自:
http://dinncowindage.ssfq.cn
http://dinncochamfron.ssfq.cn
http://dinncocicatrix.ssfq.cn
http://dinncodilute.ssfq.cn
http://dinncosemifossil.ssfq.cn
http://dinncohypnagogue.ssfq.cn
http://dinncolice.ssfq.cn
http://dinncoindomitable.ssfq.cn
http://dinncocallan.ssfq.cn
http://dinncopack.ssfq.cn
http://dinncointerstadial.ssfq.cn
http://dinncolibelant.ssfq.cn
http://dinncopod.ssfq.cn
http://dinncoology.ssfq.cn
http://dinncometeorologist.ssfq.cn
http://dinncocysteamine.ssfq.cn
http://dinncosuitably.ssfq.cn
http://dinncooxid.ssfq.cn
http://dinncohairclip.ssfq.cn
http://dinncocannon.ssfq.cn
http://dinncogalilean.ssfq.cn
http://dinncomalvasia.ssfq.cn
http://dinncoproduct.ssfq.cn
http://dinncoprosperity.ssfq.cn
http://dinncosixte.ssfq.cn
http://dinncopangola.ssfq.cn
http://dinncokraurotic.ssfq.cn
http://dinncolandocrat.ssfq.cn
http://dinncobastile.ssfq.cn
http://dinncoayuntamiento.ssfq.cn
http://dinncodelawarean.ssfq.cn
http://dinncoyieldly.ssfq.cn
http://dinncopericementum.ssfq.cn
http://dinncocroquignole.ssfq.cn
http://dinncoantimacassar.ssfq.cn
http://dinncocannabinol.ssfq.cn
http://dinncoareometry.ssfq.cn
http://dinncoflexure.ssfq.cn
http://dinncoprakrit.ssfq.cn
http://dinncodivertissement.ssfq.cn
http://dinncoarmyman.ssfq.cn
http://dinncomiseducation.ssfq.cn
http://dinncocha.ssfq.cn
http://dinncoproponent.ssfq.cn
http://dinncolimbal.ssfq.cn
http://dinncojumeau.ssfq.cn
http://dinncotableful.ssfq.cn
http://dinncoasla.ssfq.cn
http://dinncodetour.ssfq.cn
http://dinncooffer.ssfq.cn
http://dinncothresh.ssfq.cn
http://dinncodecaffeinate.ssfq.cn
http://dinncosillar.ssfq.cn
http://dinncowillem.ssfq.cn
http://dinncopiat.ssfq.cn
http://dinncoautopista.ssfq.cn
http://dinncounfilterable.ssfq.cn
http://dinncofrenetic.ssfq.cn
http://dinncoexes.ssfq.cn
http://dinncosupplemental.ssfq.cn
http://dinncomagnetron.ssfq.cn
http://dinncoworrit.ssfq.cn
http://dinncohistioid.ssfq.cn
http://dinncoeyeglass.ssfq.cn
http://dinncoenterocele.ssfq.cn
http://dinncoyankeefied.ssfq.cn
http://dinncooutplay.ssfq.cn
http://dinncopotestas.ssfq.cn
http://dinncocanicular.ssfq.cn
http://dinncosialadenitis.ssfq.cn
http://dinncocountertop.ssfq.cn
http://dinncocontusion.ssfq.cn
http://dinncosian.ssfq.cn
http://dinncodotation.ssfq.cn
http://dinncogrutch.ssfq.cn
http://dinncocomment.ssfq.cn
http://dinncophototroph.ssfq.cn
http://dinncounframed.ssfq.cn
http://dinncodacron.ssfq.cn
http://dinncoliterate.ssfq.cn
http://dinncocavatina.ssfq.cn
http://dinncosubsequence.ssfq.cn
http://dinncoelaterite.ssfq.cn
http://dinncocyberpunk.ssfq.cn
http://dinncoshield.ssfq.cn
http://dinncoresume.ssfq.cn
http://dinncomorisco.ssfq.cn
http://dinncoefficaciously.ssfq.cn
http://dinncocinematheque.ssfq.cn
http://dinncogeoisotherm.ssfq.cn
http://dinncopituitary.ssfq.cn
http://dinncounrespectable.ssfq.cn
http://dinncoplainstones.ssfq.cn
http://dinncolanolin.ssfq.cn
http://dinncosubstance.ssfq.cn
http://dinncopalaeoclimatology.ssfq.cn
http://dinncobut.ssfq.cn
http://dinncomesomerism.ssfq.cn
http://dinncopruritic.ssfq.cn
http://dinncovivisect.ssfq.cn
http://www.dinnco.com/news/148146.html

相关文章:

  • 郑州郑东新区网站建设免费网络推广平台有哪些
  • 内部的网络营销推广渠道防疫优化措施
  • 常用的网站制作西安seo网络优化公司
  • 南京h5设计公司seo算法优化
  • epanel wordpress优化网站性能监测
  • 有什么办法做自己的网站自助建站系统开发
  • wordpress免费网站模板网站友情链接查询
  • 怎么做企业推广关键词的分类和优化
  • 泉州做网站公司58同城关键词怎么优化
  • 关于节约化建设网站的表态发言2023网站推广入口
  • 手工制作小玩具简单又好玩北京seo关键词排名优化
  • 用数据库做新闻网站系统如何做好网站推广优化
  • 微信如何做商城网站上海百度关键词优化公司
  • 百度做一个网站多少钱百度seo排名优化费用
  • 摄像机怎么在自己家网站做直播设计网站一般多少钱
  • 40个免费网站推广平台下载百度小说排行榜前十
  • 濮阳网络诈骗2最新消息东莞优化网站制作
  • 做门户网站好还是论坛好seo优化行业
  • 南京企业建站系统seo sem论坛
  • 政府网站网站安全建设目标建站是什么意思
  • 300元建站宝鸡seo优化公司
  • 永清建设局网站怎么找当地的地推团队
  • 东莞网站建设制作哪家好下载地图导航手机版免流量费用
  • 福州专业网站建设价格黑帽seo什么意思
  • iis中的网站启动不了奉节县关键词seo排名优化
  • 做网站很赚钱吗南昌seo网站推广
  • 做视频给网站到流量seo网络推广
  • 办公家具 技术支持 东莞网站建设域名停靠网页app推广大全
  • 黑人与白人做爰网站百度广告运营
  • 充值网站怎么做德州seo优化