伪造Http请求IP地址
注意:伪造Http请求IP地址一般为非推荐使用手段
一般使用:简单投票网站重复投票,黑别人网站
在项目开发中(web项目),我负责的系统(简称PC),需要调其它系统接口,并且该系统需要获取客户端(浏览器访问端)的IP地址,给我愁死了,
正常流程:浏览器---访问PC系统----PC系统需要调第三方系统,此时默认情况下,PC发起的request请求IP地址是PC所在服务器的IP地址,而不是请求浏览器端的IP地址
所以,就想着是否能把request里的IP地址给修改了,因为在PC系统里是能获取到请求IP地址的,结果是修改不了
最后了解到:可以在http请求头里,追加一个头信息(名称:x-forwarded-for),它会位于原始IP地址之前,所以当第三方系统获取地址时,就获取到了真实的浏览器访问地址IP了
本代码以java为列:
X-Forwarded-For:简称XFF头,它代表客户端,也就是HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载均衡服务器时才会添加该项。
httpPost.addHeader("x-forwarded-for",ip);
详细代码如下:
- package com.sh.portal.framework.client.http;
- import java.io.IOException;
- import org.apache.commons.lang.StringUtils;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.config.RequestConfig;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClientBuilder;
- import org.apache.http.message.BasicHeader;
- import org.apache.http.protocol.HTTP;
- import org.apache.http.util.EntityUtils;
- import org.springframework.stereotype.Component;
- import com.sh.portal.framework.client.RemoteServerArgs;
- import com.sh.portal.framework.client.RemoteServerClient;
- import com.sh.portal.framework.client.RemoteServerResponse;
- import com.sh.portal.util.CommonUtils;
- @Component
- public class RemoteServerClientImpl implements RemoteServerClient {
- private static final String DEFAULT_ENCODE = "UTF-8";
- private static final String APPLICATION_JSON = "application/json";
- @Override
- public RemoteServerResponse post(RemoteServerArgs args) throws IOException {
- String ip = CommonUtils.getRequestIpAddress();
- // 创建HttpClientBuilder
- HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
- // HttpClient
- CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
- // 请求参数
- StringEntity entity = new StringEntity(args.getRequestJson(), DEFAULT_ENCODE);
- entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON));
- HttpPost httpPost = new HttpPost(args.getUrl());
- httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON);
- //此处区别PC终端类型
- httpPost.addHeader("typeFlg", "9");
- //此处增加浏览器端访问IP
- if(!ip.equals("")){
- httpPost.addHeader("x-forwarded-for",ip);
- }
- httpPost.setEntity(entity);
- httpPost.setConfig(RequestConfig.DEFAULT);
- HttpResponse httpResponse;
- // post请求
- httpResponse = closeableHttpClient.execute(httpPost);
- HttpEntity httpEntity = httpResponse.getEntity();
- RemoteServerResponse response;
- if (httpEntity != null) {
- response = new RemoteServerResponse(httpResponse.getStatusLine().getStatusCode(),
- EntityUtils.toString(httpEntity, DEFAULT_ENCODE));
- } else {
- response = new RemoteServerResponse(httpResponse.getStatusLine().getStatusCode(),
- StringUtils.EMPTY);
- }
- //释放资源
- closeableHttpClient.close();
- return response;
- }
- }
伪造Http请求IP地址的更多相关文章
- 服务端如何获取客户端请求IP地址
服务端获取客户端请求IP地址,常见的包括:x-forwarded-for.client-ip等请求头,以及remote_addr参数. 一.remote_addr.x-forwarded-for.cl ...
- 服务端如何安全获取客户端请求IP地址
服务端如何获取客户端请求IP地址,网上代码一搜一大把.其中比较常见有x-forwarded-for.client-ip等请求头,及remote_addr参数,那么为什么会存在这么多获取方式,以及到底怎 ...
- 获取客户端的请求IP地址
获取客户端的请求IP地址 package com.microClass.util; import javax.servlet.http.HttpServletRequest; import java. ...
- 伪造http的ip地址,突破ip限制的投票程序
某WEB投票程序, 使用 ip 限制和cookie限制技术,来限制每个ip每天只能投一次票,使用的是php开发,获取访问者的 ip 使用了搜狐的接口: http://txt.go.sohu.com/i ...
- java获取客户端请求IP地址(公网ip)
之前写了一个获取ip地址的方法,但是放网上一查显示此Ip地址是局域网ip地址,要是想获取请求端的真实公网ip地址怎么样了,看了一些别人的博客后发现,想要获取客户端的公网ip必须借助第三方. packa ...
- ASP.NET 查询客户端请求IP地址
public class CheckIP { #region 获取浏览器版本号 /// <summary> /// 获 ...
- openresty(nginx)中使用lua脚本获取请求IP地址的代码
人狠话不多,直接上代码:------------------------------------------------------------------------------------- lo ...
- PXE DHCP获取IP与传统DHCP获取IP地址的区别
正常的DHCP获取IP的流程(Discover-Offer-Request-Ack): (Discovery)主机端在LAN中发布MAC地址为FF:FF:FF:FF:FF:FF的广播来寻找DHCP服务 ...
- MAC地址与IP地址的区别
介绍一下MAC地址的知识,MAC地址和IP地址的区别以及MAC地址在实际应用中所涉及到的安全问题. 一.基础知识 如今的网络是分层来实现的,就像是搭积木一样,先设计某个特定功能的模块,然后把模块拼起来 ...
随机推荐
- c#做的查找文件夹内内容的小工具
第一次写博客有点激动啊QAQ 来新单位,一直没活干,公司代码控制器太多,其中有很多文件夹,每次找一个控制器都老找不到,我又不愿意用VS的全局搜索,想着没事就做了个查找控制器的小工具.代码如下: 先添加 ...
- Vue1.0基础学习笔记整理
最近一直在使用Vue.js开发项目,现将在学习过程中遇到的一些学习小细节总结如下: 1.只处理单次插值,今后的数据变化就不会再引起插值更新了 <span>This will never c ...
- 译:面试投行的20个Java问题
原文链接:https://dzone.com/articles/var-work-in-progress 作者:Anghel Leonard 译者:沈歌 如果你需要准备面试,可以看一下这篇博客中20个 ...
- 转 【<meta name="description" content=">】作用讲解
今天在看别人写的网站代码,发现类似<meta name="Keywords" content="" >.<meta name="De ...
- chosen下拉框插件的使用
效果如下 第一步: 第二步: 根据HTML5规范, 通常在引入CSS和JS时不需要指明 type,因为 text/css 和 text/javascript 分别是他们的默认值. <link r ...
- Linux虚拟系统安装——Ubuntu18.04 & CentOS6.5
Linux虚拟系统安装--Ubuntu18.04 & CentOS6.5 摘要:Linux简介.虚拟系统安装.系统备份与文件介绍 1. Linux简介 (1)1968年,MIT.Bell实验室 ...
- java实现链表结构详细代码
一.数据准备 1. 定义节点 2. 定义链表 1.数据部分 2.节点部分 class DATA //数据节点类型 { String key; String name; int age; } cla ...
- MyISAM引擎表出现“Error 'Incorrect key file for table”
mysql主从复制中的从库突然出现了警报,sql_thread停止了,show slave status\G;查看 mysql> show slave status\G ; . row **** ...
- 如何在PB中调用 Microsoft WEB 浏览器 控件?
PB中使用Microsoft Web Browser控件步骤: 在pb的某窗口中加入OLE对象,选择Insert control(插入控件),然后选中"Microsoft WEB 浏览器&q ...
- 【转】ssh timed out 超时解决方案
转自:http://www.cnblogs.com/niutouzdq/p/4091268.html 在使用阿里云ECS服务器的时候,winsftp经常被服务器断开,想必是过一会没有操作,防火墙喜欢对 ...