如何伪造Python中的soap响应?

如何伪造Python中的soap响应?,第1张

概述我正在尝试测试公司产品中的功能.我们的软件将发出如下SOAP请求: 请求标题 POST /testfunction.php HTTP/1.1Accept: application/soap+xml, application/xml, text/xmlSOAPAction: "http://www.abc.com/testfunction#test"Host: soap.abc.comCon 我正在尝试测试公司产品中的功能.我们的软件将发出如下SOAP请求:

请求标题

POST /testfunction.PHP http/1.1Accept: application/soap+xml,application/xml,text/xmlSOAPAction: "http://www.abc.com/testfunction#test"Host: soap.abc.comContent-Length: 461Connection: Keep-Alive

请求内容

<?xml version="1.0" enCoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.abc.com/testfunction"><SOAP-ENV:Body><ns1:test><productID>3</productID><productSubID>1</productSubID><version>1.0.1</version><serialNumber/><language>EN</language><dayslicensed>0</dayslicensed><daysleft>0</daysleft></ns1:test></SOAP-ENV:Body></SOAP-ENV:Envelope>

SOAP服务应该响应

响应标题

http/1.1 200 OKServer: Nginx/0.7.67Date: Mon,02 May 2011 13:43:46 GMTContent-Type: text/xml; charset=utf-8Connection: keep-aliveX-Powered-By: PHP/5.3.3-1ubuntu9.3Content-Length: 304content-encoding: gzip

响应内容

<?xml version="1.0" enCoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.abc.com/testfunction"><SOAP-ENV:Body><ns1:testResponse><result>1000</result></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

一开始我以为我可以在web.py中创建一个Web服务,并在有人在http://www.abc.com/testfunction发出POST请求时返回相同的响应.

import web                                                                                                                                                                                                                                                                                                                                                                                                                    url = (                                                                                                                                                                                                                                                                                                                                                                                           '/testfunction','testfunction',)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        class testfunction:                                                                                                                                                                                                 def POST(self):                                                                                                                                                                                                    web.header('Content-Type','text/xml; charset=utf-8')                                                                                                                                                         return """<?xml version="1.0" enCoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.abc.com/testfunction"><SOAP-ENV:Body><ns1:testResponse><result>1000</result></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>                               """                                                                                                                                                                                            app = web.application(url,globals())                                                                                                                                                                          if __name__== "__main__":                                                                                                                                                                                          app.run()

但它没有用.我想这可能与标题有关.然后我尝试使用SimpleXMLRPCServer.

from SimpleXMLRPCServer import SimpleXMLRPCServer,SimpleXMLRPCRequestHandlerimport xmlrpclibclass MyRequestHandler(SimpleXMLRPCRequestHandler):    rpc_paths = ('/',)    def do_POST(self):        return SimpleXMLRPCRequestHandler.do_POST(self)def test():    return "hello,world"server = SimpleXMLRPCServer(        ("0.0.0.0",80),requestHandler = MyRequestHandler,)   server.register_function(test,'test')server.serve_forever()

但问题是我不知道如何在标题中处理SOAPAction,而客户端在这里没有使用测试函数.谁能帮我?非常感谢!!

更新:

终于做到了,使用以下代码:

from wsgiref.simple_server import WsgiServer,WsgiRequestHandlerdef echo(environ,start_response):    status = "200 OK"    headers = [("Content-type","text/xml")]    start_response(status,headers)    return ["""<?xml version="1.0" enCoding="UTF-8"?>    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.abc.com/testfunction"><SOAP-ENV:Body><ns1:testResponse><result>1000</result></ns1:testResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>"""]httpd = WsgiServer(('0.0.0.0',WsgiRequestHandler)httpd.set_app(echo)httpd.serve_forever()

它应该与web.py代码一样,但web.py没有.从wireshark中捕获的包中,我在xml内容之前和之后发现了一些乱码(“3bc”和“0”),与编码有关?

解决方法 您可以使用 soaplib创建一个真正的SOAP服务,该服务实现您的接口并返回虚拟数据.这应该更容易维护,然后创建手写静态响应,并且代码不应该比基于web.py的示例更长.

这是Hello World example.

总结

以上是内存溢出为你收集整理的如何伪造Python中的soap响应?全部内容,希望文章能够帮你解决如何伪造Python中的soap响应?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1192529.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存