com.h3xstream.retirejs.repo.ScannerFacade Maven / Gradle / Ivy
package com.h3xstream.retirejs.repo;
import com.esotericsoftware.minlog.Log;
import com.h3xstream.retirejs.util.HashUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ScannerFacade {
private VulnerabilitiesRepository repo;
private static ScannerFacade instance; //Singleton instance
private ScannerFacade() throws IOException {
this.repo = new VulnerabilitiesRepositoryLoader().load();
}
/**
* For testing purpose only
* @param repo Mock repository (For testing purpose)
* @throws IOException Unable to load the repository
*/
public ScannerFacade(VulnerabilitiesRepository repo) throws IOException {
this.repo = repo;
}
/**
* Obtain the singleton instance. It make sure the repo is loaded the first time.
* @return Will always return the same instance
* @throws IOException Unable to load the repository
*/
public static ScannerFacade getInstance() throws IOException {
if(instance == null) {
instance = new ScannerFacade();
}
return instance;
}
/**
* Look for potential script in the HTML code <script src="//cdn.server.com/jquery/1.3.3.7.js"></script>
* @param respBytes Content of the JavaScript file (exclude HTTP headers)
* @param offset
* @return
*/
public List scanHtml(byte[] respBytes, int offset) {
String contentString = new String(respBytes,offset,respBytes.length-offset);
List res = new ArrayList();
for(String url : findScriptUrl(contentString)) {
res.addAll(scanPath(url));
}
return res;
}
private List findScriptUrl(String source) {
String[] tokens = source.split("");
List urls = new ArrayList();
for(String line : tokens) {
if(line.contains("