(byte[] request, String name, String value, boolean addIfNotPresent)
| 34 | } |
| 35 | |
| 36 | public static byte[] setHeader(byte[] request, String name, String value, boolean addIfNotPresent) { |
| 37 | if (addIfNotPresent) { |
| 38 | return Utilities.addOrReplaceHeader(request, name, value); |
| 39 | } else { |
| 40 | return Utilities.setHeader(request, name, value); |
| 41 | } |
| 42 | |
| 43 | // // find the end of the headers |
| 44 | // String prev = ""; |
| 45 | // int i = 0; |
| 46 | // while (i < request.length) { |
| 47 | // char thisChar = (char) request[i]; |
| 48 | // if (prev.equals("\n") && thisChar == '\n') { |
| 49 | // break; |
| 50 | // } |
| 51 | // if (prev.equals("\r") && thisChar == '\n' && request[i - 2] == '\n') { |
| 52 | // break; |
| 53 | // } |
| 54 | // prev = String.valueOf(thisChar); |
| 55 | // i++; |
| 56 | // } |
| 57 | // int bodyStart = i; |
| 58 | // |
| 59 | // // walk over the headers and change as appropriate |
| 60 | // String headers = new String(Arrays.copyOfRange(request, 0, bodyStart), StandardCharsets.UTF_8); |
| 61 | // String[] headersArray = headers.split("\r?\n"); |
| 62 | // boolean modified = false; |
| 63 | // for (int j = 0; j < headersArray.length; j++) { |
| 64 | // int valueStart = headersArray[j].indexOf(": "); |
| 65 | // if (valueStart != -1) { |
| 66 | // String headerNameFound = headersArray[j].substring(0, valueStart); |
| 67 | // if (headerNameFound.equals(name)) { |
| 68 | // String newValue = headerNameFound + ": " + value; |
| 69 | // if (!newValue.equals(headersArray[j])) { |
| 70 | // headersArray[j] = newValue; |
| 71 | // modified = true; |
| 72 | // } |
| 73 | // } |
| 74 | // } |
| 75 | // } |
| 76 | // |
| 77 | // // stitch the request back together |
| 78 | // byte[] modifiedRequest; |
| 79 | // if (modified) { |
| 80 | // modifiedRequest = concatenate(Utilities.helpers.stringToBytes(String.join("\r\n", headersArray) + "\r\n"), Arrays.copyOfRange(request, bodyStart, request.length)); |
| 81 | // } else if (addIfNotPresent) { |
| 82 | // IRequestInfo requestInfo = Utilities.helpers.analyzeRequest(request); |
| 83 | // int realStart = requestInfo.getBodyOffset(); |
| 84 | // modifiedRequest = concatenate(Arrays.copyOfRange(request, 0, realStart - 2), Utilities.helpers.stringToBytes(name + ": " + value + "\r\n\r\n")); |
| 85 | // modifiedRequest = concatenate(modifiedRequest, Arrays.copyOfRange(request, realStart, request.length)); |
| 86 | // } else { |
| 87 | // modifiedRequest = request; |
| 88 | // } |
| 89 | // |
| 90 | // return modifiedRequest; |
| 91 | } |
| 92 | |
| 93 | public static void launchPassiveScan(IHttpRequestResponse attack) { |
no outgoing calls
no test coverage detected