目的,只是一個 POC(目前)自動并定期在 maven 存盤庫中查找一些 CVE 標簽。
我可以通過瀏覽器和 mvn 很好地訪問 maven,但無法通過 Java 做同樣的事情,我錯過了什么?我已經嘗試過 UrlConnection、HttpsURLConnection,有和沒有 GET、Content-type、User-Agent 和 Accept,它總是為我嘗試的所有地址回傳 403,相同的代碼在“cve.mitre. org”或“nvd.nist.gov”,但“https://mvnrepository.com/artifact/log4j/apache-log4j-extras/1.2.17”失敗。
我的 URL 是動態構建的,以 "** https://mvnrepository.com/artifact/**"開頭,然后添加組、名稱和版本,將其轉換為有效地址,如 "https:// /mvnrepository.com/artifact/log4j/apache-log4j-extras/1.2.17"
System.setProperty("https.proxyHost", "xxxx");
System.setProperty("https.proxyPort", "xxxx");
String content = null;
try {
URL obj = new URL(address);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
con.setRequestProperty("Accept", "*/*");
con.connect();
BufferedReader br;
if (con.getResponseCode() < 300) {
br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
} else {
br = new BufferedReader(new InputStreamReader(con.getErrorStream(), StandardCharsets.UTF_8));
}
final StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
uj5u.com熱心網友回復:
本網站使用反機器人安全CloudFlare。
如何繞過CloudFlare 機器人保護?
這取決于.... 有時這是非常困難的任務或不可能的。您需要做的是使用瀏覽器模擬真實用戶。
使用htmlunit瀏覽器,您只能在這種情況下繞過它,并使用良好的 IP 地址。(我使用自己的 IP 地址,只做了一個請求)
你需要maven依賴:
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.57.0</version>
</dependency>
這里有一些java示例:
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;
import java.net.URL;
import java.util.List;
public class Maven {
public static void main(String[] args) throws IOException {
try (final WebClient webClient = new WebClient()) {
webClient.getOptions().setJavaScriptEnabled(false);
URL target = new URL("https://mvnrepository.com/artifact/log4j/apache-log4j-extras/1.2.17");
final HtmlPage page = webClient.getPage(target);
List<HtmlAnchor> elements = page.getByXPath("//a[contains(@class, 'vuln')]");
elements.forEach(element -> System.out.println(element.getTextContent()));
}
}
}
輸出:
CVE-2022-23305
CVE-2022-23302
CVE-2021-4104
CVE-2019-17571
View 1 more ...
4 vulnerabilities
我希望我能夠幫助你。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/492309.html
下一篇:抓取網頁資訊
