Skip to content

Commit 61efba8

Browse files
author
isayan
committed
OpenBrowser プロファイル名にてリスト表示
1 parent 3eeb2b4 commit 61efba8

File tree

3 files changed

+88
-32
lines changed

3 files changed

+88
-32
lines changed

release/YaguraExtension-v3.1.jar

871 Bytes
Binary file not shown.

src/main/java/extend/util/external/BurpBrowser.java

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package extend.util.external;
22

3+
import burp.BurpExtension;
34
import burp.api.montoya.MontoyaApi;
45
import com.google.gson.JsonArray;
56
import com.google.gson.JsonElement;
@@ -188,7 +189,7 @@ public static void copyBrowserExtension() throws IOException {
188189
}
189190
}
190191

191-
public List<String> getBrowserExecAndArgs(String profile, int port) {
192+
public List<String> getBrowserExecAndArgs(String profileKey, int port) {
192193
// chrome://version/ から情報取得
193194
final List<String> CHROME_ARGS = List.of(
194195
"--disable-ipc-flooding-protection",
@@ -218,13 +219,14 @@ public List<String> getBrowserExecAndArgs(String profile, int port) {
218219
"--no-service-autorun",
219220
"--media-cache-size=0",
220221
"--use-fake-device-for-media-stream",
221-
"--dbus-stub --disable-background-networking",
222+
"--dbus-stub",
223+
"--disable-background-networking",
222224
"--disable-features=ChromeWhatsNewUI,HttpsUpgrades,ImageServiceObserveSyncDownloadStatus",
223225
String.format("--proxy-server=localhost:%d", port),
224226
"--proxy-bypass-list=<-loopback>",
225227
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.6778.86 Safari/537.36",
226228
String.format("--user-data-dir=%s", getBrowseUserDataDirectory().toString()),
227-
String.format("--profile-directory=%s", profile),
229+
String.format("--profile-directory=%s", profileKey),
228230
"--ignore-certificate-errors",
229231
"--disable-features=TrackingProtection3pcd,LensOverlay",
230232
String.format("--load-extension=%s", getBrowseExtensionDirectory().toString()),
@@ -236,7 +238,7 @@ public List<String> getBrowserExecAndArgs(String profile, int port) {
236238
return chromeExecAndArg;
237239
}
238240

239-
public File[] getUserProfile() {
241+
public File[] getBrowserProfileDirectory() {
240242
File file = getBrowseUserDataDirectory().toFile();
241243
File[] profiles = file.listFiles(new FileFilter() {
242244

@@ -263,9 +265,9 @@ public int compare(File f1, File f2) {
263265
return profiles;
264266
}
265267

266-
public void openBrowser(String profile, int port) {
268+
public void openBrowser(String profileKey, int port) {
267269
try {
268-
List<String> chromeExeAndArg = getBrowserExecAndArgs(profile, port);
270+
List<String> chromeExeAndArg = getBrowserExecAndArgs(profileKey, port);
269271
ProcessBuilder process = new ProcessBuilder(chromeExeAndArg);
270272
process.start();
271273
} catch (IOException ex) {
@@ -275,35 +277,81 @@ public void openBrowser(String profile, int port) {
275277

276278
private Path getBrowserProfilePath() {
277279
Path path = getBrowseUserDataDirectory();
278-
return path.resolve("Local State");
280+
return path.resolve(BURP_CHROMIUM_STATE);
279281
}
280282

281-
public Map<String, BrowserProfile> getBrowserProfile() throws IOException {
282-
Path path = getBrowserProfilePath();
283-
return getBrowserProfile(path);
283+
public Map<String, BrowserProfile> getBrowserProfile() {
284+
try {
285+
Path path = getBrowserProfilePath();
286+
return getBrowserProfile(path);
287+
}
288+
catch (IOException ex) {
289+
File[] profiles = this.getBrowserProfileDirectory();
290+
Map<String, BrowserProfile> order_profile = new LinkedHashMap<>();
291+
for (File p : profiles) {
292+
BrowserProfile profile = new BrowserProfile();
293+
profile.setName(p.getName());
294+
order_profile.put(p.getName(), profile);
295+
}
296+
return order_profile;
297+
}
284298
}
285299

286300
/**
287301
*
302+
* @param path
288303
* @return
304+
* @throws java.io.IOException
289305
*/
290-
public static Map<String, BrowserProfile> getBrowserProfile(final Path path) throws IOException {
306+
protected static Map<String, BrowserProfile> getBrowserProfile(final Path path) throws IOException {
291307
String config = FileUtil.stringFromFile(path.toFile(), StandardCharsets.UTF_8);
292308
JsonObject root_json = JsonUtil.parseJsonObject(config);
293-
JsonObject profile_json = root_json.getAsJsonObject("profile").getAsJsonObject("info_cache");
294-
JsonArray profile_order = root_json.getAsJsonObject("profile").getAsJsonArray("profiles_order");
295-
Map<String, JsonElement> profile_map = profile_json.asMap();
296-
Map<String, BrowserProfile> order_profile = new LinkedHashMap<>();
297-
for (int i = 0; i < profile_order.size(); i++) {
298-
JsonElement key = profile_order.get(i);
299-
JsonElement profile = profile_map.get(key.getAsString());
300-
BrowserProfile prowserProfile = JsonUtil.jsonFromJsonElement(profile, BrowserProfile.class, true);
301-
order_profile.put(key.getAsString(), prowserProfile);
309+
JsonObject profile_info = root_json.getAsJsonObject("profile").getAsJsonObject("info_cache");
310+
JsonArray profiles_order = root_json.getAsJsonObject("profile").getAsJsonArray("profiles_order");
311+
Map<String, JsonElement> profile_map = profile_info.asMap();
312+
Map<String, BrowserProfile> browser_profile = new LinkedHashMap<>();
313+
for (int i = 0; i < profiles_order.size(); i++) {
314+
JsonElement profile_key_json = profiles_order.get(i);
315+
String profile_key = profile_key_json.getAsString();
316+
if (profile_key.startsWith("Profile ")) {
317+
JsonElement profile_entry = profile_map.get(profile_key);
318+
BrowserProfile prowserProfile = JsonUtil.jsonFromJsonElement(profile_entry, BrowserProfile.class, true);
319+
prowserProfile.setProfileKey(profile_key);
320+
browser_profile.put(profile_key, prowserProfile);
321+
}
302322
}
303-
return order_profile;
323+
return browser_profile;
304324
}
305325

306-
static class BrowserProfile {
326+
public static class BrowserProfile {
327+
328+
public final static BrowserProfile DEFAULT;
329+
public final static BrowserProfile GUEST;
330+
331+
static {
332+
DEFAULT = new BrowserProfile();
333+
DEFAULT.profileKey = BROWSER_PROFILE_DEFAULT;
334+
DEFAULT.name = BROWSER_PROFILE_DEFAULT;
335+
GUEST = new BrowserProfile();
336+
GUEST.profileKey = BROWSER_PROFILE_GUEST;
337+
GUEST.name = BROWSER_PROFILE_GUEST;
338+
}
339+
340+
private String profileKey;
341+
342+
/**
343+
* @return the profile
344+
*/
345+
public String getProfileKey() {
346+
return profileKey;
347+
}
348+
349+
/**
350+
* @param profileKey the profile to set
351+
*/
352+
public void setProfileKey(String profileKey) {
353+
this.profileKey = profileKey;
354+
}
307355

308356
@Expose
309357
private String name;
@@ -322,6 +370,11 @@ public void setName(String name) {
322370
this.name = name;
323371
}
324372

373+
@Override
374+
public String toString() {
375+
return name;
376+
}
377+
325378
}
326379

327380
}

src/main/java/yagura/view/BurpToolBar.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
import extension.burp.BurpUtil;
99
import extension.helpers.FileUtil;
1010
import extension.helpers.StringUtil;
11-
import java.awt.Component;
12-
import java.awt.Container;
1311
import java.awt.Point;
1412
import java.io.File;
1513
import java.io.IOException;
1614
import java.nio.charset.StandardCharsets;
15+
import java.util.Map;
1716
import java.util.logging.Level;
1817
import java.util.logging.Logger;
18+
import javax.swing.DefaultComboBoxModel;
1919
import javax.swing.JFileChooser;
2020
import javax.swing.JOptionPane;
2121
import javax.swing.JTabbedPane;
@@ -242,7 +242,10 @@ public void stateChanged(ChangeEvent e) {
242242

243243
};
244244

245+
private final DefaultComboBoxModel modelProfilel = new DefaultComboBoxModel();
246+
245247
private void customizeComponents() {
248+
this.cmbProfile.setModel(this.modelProfilel);
246249
this.renewProfile();
247250
JToggleButton button = BurpUtil.findSuiteIntercept(BurpUtil.suiteFrame());
248251
if (button != null) {
@@ -253,13 +256,13 @@ private void customizeComponents() {
253256
}
254257

255258
public void renewProfile() {
256-
File[] profiles = this.browser.getUserProfile();
257-
this.cmbProfile.removeAllItems();
258-
this.cmbProfile.addItem(BurpBrowser.BROWSER_PROFILE_DEFAULT);
259-
for (File p : profiles) {
260-
this.cmbProfile.addItem(p.getName());
259+
this.modelProfilel.removeAllElements();
260+
this.modelProfilel.addElement(BurpBrowser.BrowserProfile.DEFAULT);
261+
Map<String, BurpBrowser.BrowserProfile> profiles = this.browser.getBrowserProfile();
262+
for (Map.Entry<String, BurpBrowser.BrowserProfile> entry : profiles.entrySet()) {
263+
this.modelProfilel.addElement(entry.getValue());
261264
}
262-
this.cmbProfile.addItem(BurpBrowser.BROWSER_PROFILE_GUEST);
265+
this.modelProfilel.addElement(BurpBrowser.BrowserProfile.GUEST);
263266
}
264267

265268
private void tglInterceptStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tglInterceptStateChanged
@@ -281,10 +284,10 @@ private void tglInterceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
281284
private void btnOpenBrowserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenBrowserActionPerformed
282285
try {
283286
BurpBrowser.copyBrowserExtension();
284-
String profile = (String) this.cmbProfile.getSelectedItem();
287+
BurpBrowser.BrowserProfile profile = (BurpBrowser.BrowserProfile) this.modelProfilel.getSelectedItem();
285288
BurpConfig.RequestListener listener = BurpConfig.openBrowserRequestListener(api, 8080);
286289
if (listener != null) {
287-
browser.openBrowser((profile == null) ? BurpBrowser.BROWSER_PROFILE_DEFAULT : profile, listener.getListenerPort());
290+
browser.openBrowser((profile == null) ? BurpBrowser.BROWSER_PROFILE_DEFAULT : profile.getProfileKey(), listener.getListenerPort());
288291
} else {
289292
JOptionPane.showMessageDialog(null, "fail Open Browser");
290293
}

0 commit comments

Comments
 (0)