11package extend .util .external ;
22
3+ import burp .BurpExtension ;
34import burp .api .montoya .MontoyaApi ;
45import com .google .gson .JsonArray ;
56import 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}
0 commit comments