其他分享
首页 > 其他分享> > 【PoRE】Lab7: Packet Sniffing

【PoRE】Lab7: Packet Sniffing

作者:互联网

回到目录

内容总结

Lab简介与参考

  关于BurpSuite拦截和修改报文的方法,大家可以查看另一篇学姐写的博客。链接见注释1

  以修改Smali代码的方法破解的话,最后的UI会显示出我们修改的学号、金钱数。这个与Task 2就会产生冲突。使用BurpSuite拦截修改的话就不会有这个问题。

package burp;

import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

public class BurpExtender implements IBurpExtender, IProxyListener {
    private static final String SecretChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
    private IExtensionHelpers helpers;
    private int flag;
    private final String name = "PoRE's BurpExtender";

    private static String encode(byte[] bArr) {
        int i;
        StringBuffer stringBuffer = new StringBuffer(((bArr.length + 7) * 8) / 5);
        int i2 = 0;
        int i3 = 0;
        while (i2 < bArr.length) {
            int i4 = bArr[i2] >= 0 ? bArr[i2] : bArr[i2] + 256;
            if (i3 > 3) {
                i2++;
                i3 = (i3 + 5) % 8;
                i = ((i4 & (255 >> i3)) << i3) | ((i2 < bArr.length ? bArr[i2] >= 0 ? bArr[i2] : bArr[i2] + 256 : 0) >> (8 - i3));
            } else {
                int i5 = i3 + 5;
                i = (i4 >> (8 - i5)) & 31;
                i3 = i5 % 8;
                if (i3 == 0) {
                    i2++;
                }
            }
            stringBuffer.append(SecretChars.charAt(i%32));
        }
        return stringBuffer.toString();
    }

    @Override
    public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
        helpers = callbacks.getHelpers();
        callbacks.setExtensionName(name);
        callbacks.registerProxyListener(this);
    }

    @Override
    public void processProxyMessage(boolean messageIsRequest, IInterceptedProxyMessage message) {
        IHttpRequestResponse request = message.getMessageInfo();
        if (messageIsRequest) {
            IRequestInfo analyzedRequest = helpers.analyzeRequest(request);
            String url = analyzedRequest.getUrl().toString();
            if ("http://49.235.197.28:80/lab7/login.php".equals(url)) {
                //TASK 2.1
                flag=0;
                byte[] requestBytes =
                        helpers.updateParameter(request.getRequest(), helpers.buildParameter("msg",
                                encode(helpers.stringToBytes("username=GUEST&password=TEMP_PASSWD")),
                                IParameter.PARAM_BODY));
                request.setRequest(requestBytes);
            }
            else if ("http://49.235.197.28:80/lab7/buySecret.php".equals(url)) {
                //TASK 2.2
                flag=1;
                byte[] requestBytes =
                        helpers.updateParameter(request.getRequest(), helpers.buildParameter("msg",
                                encode(helpers.stringToBytes("user_id=19307130005&money=12345&is_fake=0")),
                                IParameter.PARAM_BODY));
                request.setRequest(requestBytes);
            }
            else {
                // Other cases. Ignore it.
                return;
            }
        }
        else {
            if (flag == 1) {
                return;
            }
            byte[] responseBytes = request.getResponse();
            IResponseInfo analyzedResponse = helpers.analyzeResponse(responseBytes);
            int offset = analyzedResponse.getBodyOffset();
            StringBuilder stringBuilder = new StringBuilder();
            for (int i=0;i<offset;i++) {
                stringBuilder.append((char)responseBytes[i]);
            }
            String body = "{\"result\":1,\"message\":\"success\",\"id\":\"19307130005\",\"Secret1\":\"flag{e43y_p4ck37_sn1ff1Ng}\",\"money\":1}";
            stringBuilder.append(encode(helpers.stringToBytes(body)));
            byte[] returnResponse = helpers.stringToBytes(stringBuilder.toString());
            request.setResponse(returnResponse);
        }
    }
}

  至此完成了本Lab的所有内容。


  1. 请点击我 ↩︎

  2. 如果您和我一样,也是在Task 1中通过修改Smali代码实现的,那么请在Task 2中使用最初始的apk,否则会有干扰。 ↩︎

标签:Task,request,i3,i2,PoRE,BurpSuite,Sniffing,Lab7,helpers
来源: https://blog.csdn.net/Iridescent_fd/article/details/118460764