Skip to content

Commit

Permalink
opt OQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
whwlsfb committed Jan 6, 2022
1 parent f3b5558 commit 4e690e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/wanghw/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Integer call() throws Exception {
if (!result.equals("")) {
System.out.println(result);
} else {
System.out.println("empty!\r\n");
System.out.println("not found!\r\n");
}
}
System.out.println("===========================================");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/wanghw/spider/DataSource01.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.wanghw.ISpider;
import cn.wanghw.utils.HashMapUtils;
import cn.wanghw.utils.OQLSnippets;
import org.graalvm.visualvm.lib.jfluid.heap.Heap;
import org.graalvm.visualvm.lib.profiler.oql.engine.api.OQLEngine;

Expand All @@ -18,10 +19,10 @@ public String sniff(Heap heap) {
final String[] result = {""};
try {
OQLEngine oqlEngine = new OQLEngine(heap);
oqlEngine.executeQuery("select {'username':x.username.value.toString(),'password':x.password.value.toString(),'url':x.url.value.toString(),'driverClassName':x.driverClassName.value.toString()} from org.springframework.boot.autoconfigure.jdbc.DataSourceProperties x", o -> {
oqlEngine.executeQuery(OQLSnippets.getValue + "map(filter(heap.objects('org.springframework.boot.autoconfigure.jdbc.DataSourceProperties'), 'it!=null && it.driverClassName != null'), \"{'username':getValue(it.username),'password':getValue(it.password),'url':getValue(it.url),'driverClassName':getValue(it.driverClassName)}\")", o -> {
if (o instanceof HashMap) {
HashMap<String, String> hashMap = (HashMap<String, String>) o;
result[0] += HashMapUtils.dumpString(hashMap);
result[0] += HashMapUtils.dumpString(hashMap, false);
}
return false;
});
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/cn/wanghw/spider/OSS01.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@ public String getName() {
}

private static final String searchPart =
"( (x.key.toString().toLowerCase().contains('oss.') || " +
"x.key.toString().toLowerCase().contains('fileupload') || " +
"x.key.toString().toLowerCase().contains('file.upload')) && " +
"(x.key.toString().toLowerCase().contains('keyid') || x.key.toString().toLowerCase().contains('key.id') || " +
"x.key.toString().toLowerCase().contains('keysecret') || x.key.toString().toLowerCase().contains('key.secret') ||" +
"x.key.toString().toLowerCase().contains('bucketname') || " +
"x.key.toString().toLowerCase().contains('endpoint')))";
"((it.searchKey.contains('oss.') || " +
"(it.searchKey.contains('file') && " +
"it.searchKey.contains('upload')) ) && " +
"((it.searchKey.contains('key') && " +
"(it.searchKey.contains('id') || " +
"it.searchKey.contains('secret') || " +
"it.searchKey.contains('access'))) || " +
"it.searchKey.contains('bucket') || " +
"it.searchKey.contains('endpoint')))";

@Override
public String sniff(Heap heap) {
final String[] result = {""};
try {
OQLEngine oqlEngine = new OQLEngine(heap);
oqlEngine.executeQuery("select {'key': x.key.toString(), 'value': x.value.toString()} from java.util.Hashtable$Entry x where x.key != null && " + searchPart, o -> {
oqlEngine.executeQuery("filter(map(filter(heap.objects('java.util.Hashtable$Entry'),'it.key != null'), \"{'key': it.key.toString(),'searchKey': it.key.toString().toLowerCase(), 'value':it.value.toString()}\"), \"" + searchPart + "\")", o -> {
if (o instanceof HashMap) {
HashMap<String, String> hashMap = (HashMap<String, String>) o;
result[0] += hashMap.get("key") + " = " + hashMap.get("value") + "\r\n";
}
return false;
});
oqlEngine.executeQuery("select {'key': x.key.toString(), 'value': x.value.toString()} from java.util.LinkedHashMap$Entry x where x.key != null && " + searchPart, o -> {
oqlEngine.executeQuery("filter(map(filter(heap.objects('java.util.LinkedHashMap$Entry'),'it.key != null'), \"{'key': it.key.toString(),'searchKey': it.key.toString().toLowerCase(), 'value':it.value.toString()}\"), \"" + searchPart + "\")", o -> {
if (o instanceof HashMap) {
HashMap<String, String> hashMap = (HashMap<String, String>) o;
result[0] += hashMap.get("key") + " = " + hashMap.get("value") + "\r\n";
Expand Down

0 comments on commit 4e690e3

Please sign in to comment.