77import java .net .URL ;
88import java .nio .file .Path ;
99import java .util .ArrayList ;
10+ import java .util .Arrays ;
11+ import java .util .Comparator ;
1012import java .util .List ;
1113import java .util .Properties ;
1214import java .util .logging .Level ;
@@ -21,7 +23,9 @@ public class BrowserUtil {
2123
2224 private final static Logger logger = Logger .getLogger (BrowserUtil .class .getName ());
2325
24- private final static String CHROMIUM_EXTENSIONS = "/Browser/ChromiumExtension" ;
26+ public final static String PROFILE_DEFAULT = "Default" ;
27+
28+ private final static String CHROMIUM_EXTENSIONS = "resources/Browser/ChromiumExtension" ;
2529
2630 private final static String CHROMIUM_PROPERTIES = "/chromium.properties" ;
2731
@@ -130,48 +134,47 @@ public static Path getBrowsePath() {
130134 return dir .resolve (path );
131135 }
132136
133-
134137 public static List <String > getBrowserExecAndArgs (String profile , int port ) {
135138 // chrome://version/ から情報取得
136139 final List <String > CHROME_ARGS = List .of (
137- "--disable-ipc-flooding-protection" ,
138- "--disable-xss-auditor" ,
139- "--disable-bundled-ppapi-flash" ,
140- "--disable-plugins-discovery" ,
141- "--disable-default-apps" ,
142- "--disable-prerender-local-predictor" ,
143- "--disable-sync" ,
144- "--disable-breakpad" ,
145- "--disable-crash-reporter" ,
146- "--disable-prerender-local-predictor" ,
147- "--disk-cache-size=0" ,
148- "--disable-settings-window" ,
149- "--disable-notifications" ,
150- "--disable-speech-api" ,
151- "--disable-file-system" ,
152- "--disable-presentation-api" ,
153- "--disable-permissions-api" ,
154- "--disable-new-zip-unpacker" ,
155- "--disable-media-session-api" ,
156- "--no-experiments" ,
157- "--no-events" ,
158- "--no-first-run" ,
159- "--no-default-browser-check" ,
160- "--no-pings" ,
161- "--no-service-autorun" ,
162- "--media-cache-size=0" ,
163- "--use-fake-device-for-media-stream" ,
164- "--dbus-stub" ,
165- "--disable-background-networking" ,
166- "--disable-features=ChromeWhatsNewUI,HttpsUpgrades,ImageServiceObserveSyncDownloadStatus" ,
167- "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.127 Safari/537.36" ,
168- "--ignore-certificate-errors" ,
169- String .format ("--proxy-server=localhost:%d" , port ),
170- "--proxy-bypass-list=<-loopback>" ,
171- String .format ("--profile-directory=%s" , profile ),
172- String .format ("--user-data-dir=%s" , getBrowseUserDataDirectory ().toString ()),
173- String .format ("--load-extension=%s" , getBrowseExtensionDirectory ().toString ()),
174- "chrome://newtab"
140+ "--disable-ipc-flooding-protection" ,
141+ "--disable-xss-auditor" ,
142+ "--disable-bundled-ppapi-flash" ,
143+ "--disable-plugins-discovery" ,
144+ "--disable-default-apps" ,
145+ "--disable-prerender-local-predictor" ,
146+ "--disable-sync" ,
147+ "--disable-breakpad" ,
148+ "--disable-crash-reporter" ,
149+ "--disable-prerender-local-predictor" ,
150+ "--disk-cache-size=0" ,
151+ "--disable-settings-window" ,
152+ "--disable-notifications" ,
153+ "--disable-speech-api" ,
154+ "--disable-file-system" ,
155+ "--disable-presentation-api" ,
156+ "--disable-permissions-api" ,
157+ "--disable-new-zip-unpacker" ,
158+ "--disable-media-session-api" ,
159+ "--no-experiments" ,
160+ "--no-events" ,
161+ "--no-first-run" ,
162+ "--no-default-browser-check" ,
163+ "--no-pings" ,
164+ "--no-service-autorun" ,
165+ "--media-cache-size=0" ,
166+ "--use-fake-device-for-media-stream" ,
167+ "--dbus-stub" ,
168+ "--disable-background-networking" ,
169+ "--disable-features=ChromeWhatsNewUI,HttpsUpgrades,ImageServiceObserveSyncDownloadStatus" ,
170+ "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.127 Safari/537.36" ,
171+ "--ignore-certificate-errors" ,
172+ String .format ("--proxy-server=localhost:%d" , port ),
173+ "--proxy-bypass-list=<-loopback>" ,
174+ String .format ("--profile-directory=%s" , profile ),
175+ String .format ("--user-data-dir=%s" , getBrowseUserDataDirectory ().toString ()),
176+ String .format ("--load-extension=%s" , getBrowseExtensionDirectory ().toString ()),
177+ "chrome://newtab"
175178 );
176179 BurpVersion .OSType os = BurpVersion .getOSType ();
177180 List <String > chromeExecAndArg = new ArrayList <>();
@@ -183,23 +186,36 @@ public static List<String> getBrowserExecAndArgs(String profile, int port) {
183186 return chromeExecAndArg ;
184187 }
185188
186- public static void copyBrowserExtension () {
187- URL url = BrowserUtil .class .getResource (CHROMIUM_EXTENSIONS );
189+ public static void copyBrowserExtension () throws IOException {
188190 if (!existsBrowseExtensionDirectory ()) {
189-
191+ File browserExtensions = getBrowseExtensionDirectory ().toFile ();
192+ browserExtensions .mkdir ();
193+ URL burpJarUrl = BrowserUtil .class .getResource ("/" );
194+ String burpJar = ZipUtil .getBaseJar (burpJarUrl );
195+ ZipUtil .decompressZip (new File (burpJar ), browserExtensions , CHROMIUM_EXTENSIONS );
190196 }
191197 }
192198
193199 public static File [] getUserProfile () {
194200 File file = getBrowseUserDataDirectory ().toFile ();
195- File [] list = file .listFiles (new FileFilter () {
201+ File [] profiles = file .listFiles (new FileFilter () {
196202
197203 @ Override
198204 public boolean accept (File pathname ) {
199- return pathname .isDirectory () && pathname .getName ().startsWith ("Profile" );
205+ return pathname .isDirectory () && pathname .getName ().startsWith ("Profile " );
206+ }
207+
208+ });
209+ profiles = (profiles == null ) ? new File []{} : profiles ;
210+ Arrays .sort (profiles , new Comparator <File >() {
211+ @ Override
212+ public int compare (File f1 , File f2 ) {
213+ int p1 = Integer .parseInt (f1 .getName ().substring ("Profile " .length ()));
214+ int p2 = Integer .parseInt (f2 .getName ().substring ("Profile " .length ()));
215+ return p1 - p2 ;
200216 }
201217 });
202- return ( list == null ) ? new File [] {} : list ;
218+ return profiles ;
203219 }
204220
205221 public static void openBrowser (String profile , int port ) {
0 commit comments