- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用请求从网页检索某些数据时遇到一些问题。它使用 Siteminder,初始表单只有三个字段,但当我提交它时,我的密码更改为十六进制,并添加了其他字段。似乎根本无法让它发挥作用。我不断返回错误消息。
感谢您的帮助,对于这么长的帖子,我深表歉意!
编辑:包含两个 JavaScript 函数,因为它们会更改数据。
Python:
from requests import session
with session() as s:
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
payload = {
'USER': 'username',
'PASSWORD': 'pw',
'TARGET': 'https://www.THISSITE.com/pg'
}
resp = s.post('https://www.THISSITE.com/THIS/fcc/THISSITE.fcc', headers=headers, data=payload )
html = resp.text
print(html)
表格:
<form
id="login"
method="post"
name="Login"
action="https://www.THISSITE.com/THIS/fcc/THISSITE.fcc">
<input
type="hidden"
name="TARGET"
value="https://www.THISSITE.com/pg"
></input>
<div class="form-group">
<input
type="text"
id="USER"
name="USER"
value=""
></input>
<div class="form-group">
<input
type="password"
id="PASSWORD"
name="PASSWORD"
value=""
></input>
</div>
<input
type="submit"
name="OK"
value="Login"
onclick="submitAuthForm(this.form);"
></input>
submitAuthForm(表单):
function submitAuthForm(form) {
var strval = form.PASSWORD.value;
if(!isJson(strval)){
var info = {};
info["Password"] = hexEncode(strval);
form.PASSWORD.value = JSON.stringify(info);
}
}
十六进制编码(str):
function hexEncode(s){
var chrsz = 8;
var hexcase = 0;
function str2binb (str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz) {
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
}
return bin;
}
function Utf8Encode(string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
function binb2hex (binarray) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}
s = Utf8Encode(s);
return binb2hex(str2binb(s));
}
网页提交时的参数:
SMENC: UTF-8
SMLOCALE: US-EN
target: https://www.THISSITE.com/pg
smauthreason: 27
smagentname: mR2h1e4BPUPZ5eTpyZckvJXpXO1mE5RpNTYtnh9C8sMfqiHlbrnBjW2SNjbwIRz+
type:
realmoid:
smusermsg:
USER: username
PASSWORD: {"TokenId":"longstringoflettersandnumbersHEX???","Password":""}
最佳答案
hexEncode
函数获取一个字符串并转换为其 UTF8 编码表示形式的组成字节的一系列十六进制表示形式。 Python 中的等效方法是将输入的 unicode 字符串编码为 UTF-8,然后将结果重新编码为 十六进制,例如
>>> import binascii
>>> binascii.hexlify('d'.encode('utf-8'))
b'64'
>>> binascii.hexlify('¡¢£¤¥'.encode('utf-8'))
b'c2a1c2a2c2a3c2a4c2a5'
注意:在 Python 2.7 中,这将是 -
>>> 'd'.encode('utf-8').encode('hex')
'64'
>>> u'¡¢£¤¥'.encode('utf-8').encode('hex')
'c2a1c2a2c2a3c2a4c2a5'
如果您使用示例密码进行测试,它应该会产生与网站相同的输出,但有一点需要注意。
hexEncode('d')
"64000000"
请注意,Javascript 添加了许多尾随 0,使字符串的长度成为 8 的倍数。我们需要填充结果以获得相同的输出。
>>> s = binascii.hexlify('d'.encode('utf-8'))
>>> n = len(s)
>>> from math import ceil
>>> next_8_multiple = int(ceil(n/8.0) * 8)
>>> s.ljust(next_8_multiple, b'0')
b'6400000000'
我们可以将其包装在一个完整的函数中:
from math import ceil
import binascii
def hex_encode_and_pad(s):
hex = binascii.hexlify(s.encode('utf-8'))
n = len(hex)
next_8_multiple = int(ceil(n/8.0) * 8)
zeros_to_append = next_8_multiple - n
return hex.ljust(next_8_multiple, b'0')
现在,这给出了与 Javascript 函数相同的结果:
>>> hex_encode_and_pad('d')
'64000000'
下一步是将其包装在 JSON 的字符串表示形式中。您可以通过手动编码字符串+仅插入标记来做到这一点,例如
value = '{"TokenId":"%s","Password":""}' % token
或者通过从 Python 字典创建 JSON 字符串 —
import json
data = {'TokenId': token, 'Password': ''}
value = json.dumps(data)
基于上面所示示例请求的完整代码为:
import binascii
import json
from math import ceil
from requests import session
def hex_encode_and_pad(s):
hex = binascii.hexlify(s.encode('utf-8'))
n = len(hex)
next_8_multiple = int(ceil(n/8.0) * 8)
zeros_to_append = next_8_multiple - n
return hex.ljust(next_8_multiple, b'0')
with session() as s:
password = u'your_password'
token = hex_encode_and_pad(password)
data = {'TokenId': token, 'Password': ''}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
payload = {
'USER': 'username',
'PASSWORD': json.dumps(data),
'TARGET': 'https://www.THISSITE.com/pg'
}
resp = s.post('https://www.THISSITE.com/THIS/fcc/THISSITE.fcc', headers=headers, data=payload )
html = resp.text
print(html)
关于python - 将 Python 请求与 Siteminder 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52107447/
环境 Richfaces 3.3.3 JSF 1.2 站点记录器 要求 用户输入所需的申请地址。 Siteminder 拦截并询问用户名和密码。客户提供凭据。客户使用应用程序并单击注销/退出按钮。应用
当尝试在 Tomcat 6 上部署我的 Web 应用程序时,出现此错误。 这是由我的应用程序中的 SSO 直通过滤器引起的。 我的 SiteMinder 版本是 6.0.5.35。 java.lang
我们正在使用 GWT-EXT 框架,因此我需要在工具栏上显示登录用户的完整用户名。 我可以通过自定义 Web 服务(在 jars 中)的请求对象检索用户 ID,但我看不到任何可以给我完整用户名的方法。
我正在尝试编写一些代码来连接到使用 Siteminder 身份验证的 HTTPS 站点。 我一直收到 401。有什么想法吗? 我在这里阅读了一些不同的东西,但没有一个看起来真的很有帮助。我还使用 Fi
我正在尝试连接到受 SiteMinder 保护的资源。最终,该应用程序将在 PhoneGap 中,但目前,我只是在测试基本通信。当我请求资源时,SiteMinder 拦截请求并显示登录屏幕。发布用户名
有没有人有一个简单的自定义登录页面,它将发布到默认的 login.fcc。我不确定从哪里开始。大概它会有 javascript 代码来获取查询字符串的一部分,然后将其传递给 login.fcc 最佳答
在我的应用程序代码中,我使用这种 url 将用户从一个页面重定向到另一个页面:http://myhost:8001/myapp/list.jsp?name=abc'd&age=10这里的名称是用户可以
因为我正在处理调用 url 的项目,并且该 url 正在使用 siteminder,所以每次我向该 url 发出请求时 https://some-host/a/getmeta?id=10 它将我重定向
是否有将 Siteminder 与 Tomcat 一起使用的详细指南。我在 Google 上进行了搜索,因此大多数问题都没有得到解答。 最佳答案 这是 Tomcat 和 JBoss 应用程序服务器代理
我们使用 Siteminder 进行身份验证,并且使用无状态的 Angular js。 如何使 Siteminder session 无效。我在 Spring Security 中进行了如下配置。但这
我想使用 siteminder r.12 创建代理对象。想要找到以下参数的值。值存储在哪里? 代码中定义的用户定义连接参数,例如: AgentAPI 代理 = new AgentAPI(); Serv
我正在尝试使用 Python 访问和解析工作中的网站。站点授权是通过 siteminder 完成的,因此通常的 urllib/urllib2 用户密码不起作用。有谁知道如何做到这一点?谢谢诺姆M 最佳
我正在尝试使用基于 Siteminder 的 preAuth 的 spring security 来保护我的 grails 应用程序。这基本上就是我所需要的。该应用程序仅用于检查一些东西,因此不需要数
我们的系统是与 Siteminder 交互以进行身份验证并连接到后端系统的网关。 Siteminder 在标题中返回 SMSESSION 和 SMIDENTITY。如何从 SMSESSION 检索
我在使用请求从网页检索某些数据时遇到一些问题。它使用 Siteminder,初始表单只有三个字段,但当我提交它时,我的密码更改为十六进制,并添加了其他字段。似乎根本无法让它发挥作用。我不断返回错误消息
我想在一个应用程序中实现 SSO,因为我在该应用程序上有一个 SiteMinder 策略服务器,它提供登录(例如应用程序 1),并且还在其他应用程序的服务器上安装了 SiteMinder Webage
在使用 CA Siteminder 的 JAVA SDK API 时,我们注意到一个严重的问题,即有时 init 会随机失败。稍后还会重新初始化,系统不会发生任何变化。这有点令人震惊和出乎意料。由于
我见过很多示例,其中有一个带有 Angular JS 的自定义登录页面,然后我们使用用户名/密码进行 rest POST 调用,然后 Spring 根据我们提供的任何 Auth 服务进行身份验证。然后
一般来说,我对 SiteMinder 和 SSO 完全陌生。我整个下午都在 SO 和 CA 的网站上四处寻找一个基本示例,但找不到。我不关心设置或编程 SM 或类似的东西。所有这些都已经由其他人完成。
我们的 IT 人员拒绝在应用程序的 IIS 6.0 Web 服务器上安装 SiteMinder 代理,理由是它是第三方软件,存在安全问题,而且资源利用率高可能会影响应用程序性能。 他们建议我们建立一个
我是一名优秀的程序员,十分优秀!