55import io .sentry .Sentry ;
66import net .olympiccode .vhackos .api .entities .AppType ;
77import net .olympiccode .vhackos .api .entities .BruteForceState ;
8- import net .olympiccode .vhackos .api .entities .impl .BruteForceImpl ;
98import net .olympiccode .vhackos .api .exceptions .ExploitFailedException ;
109import net .olympiccode .vhackos .api .network .BruteForce ;
1110import net .olympiccode .vhackos .api .network .ExploitedTarget ;
12- import net .olympiccode .vhackos .api .network .NetworkManager ;
1311import net .olympiccode .vhackos .bot .core .BotService ;
1412import net .olympiccode .vhackos .bot .core .vHackOSBot ;
1513import org .slf4j .Logger ;
1816import javax .script .ScriptEngine ;
1917import javax .script .ScriptEngineManager ;
2018import javax .script .ScriptException ;
21- import java .nio .channels .NetworkChannel ;
2219import java .util .ArrayList ;
2320import java .util .concurrent .Executors ;
2421import java .util .concurrent .ScheduledExecutorService ;
2825public class NetworkingService implements BotService {
2926 public static ScheduledExecutorService networkingService ;
3027 Logger LOG = LoggerFactory .getLogger ("NetworkingService" );
28+ Cache <String , String > cache = CacheBuilder .newBuilder ()
29+ .maximumSize (500 )
30+ .expireAfterWrite (60 * 5 + 30 , TimeUnit .SECONDS ).build ();
3131
3232 public NetworkingService () {
3333 LOG .info ("Creating NetworkingService..." );
3434 networkingService = Executors .newScheduledThreadPool (1 , new NetworkingServiceFactory ());
3535 }
3636
37- public class NetworkingServiceFactory implements ThreadFactory {
38- public Thread newThread (Runnable r ) {
39- return new Thread (r , "vHackOSBot-NetworkingService" );
40- }
41- }
42-
43-
4437 @ Override
4538 public ScheduledExecutorService getService () {
4639 return networkingService ;
@@ -54,31 +47,28 @@ public void setup() {
5447 networkingService .scheduleAtFixedRate (() -> runService (), 0 , 60000 , TimeUnit .MILLISECONDS );
5548 }
5649
57- Cache <String , String > cache = CacheBuilder .newBuilder ()
58- .maximumSize (500 )
59- .expireAfterWrite (60 *5 +30 , TimeUnit .SECONDS ).build ();
60-
6150 public void runService () {
6251 try {
63- ((ArrayList <BruteForce >)((ArrayList )vHackOSBot .api .getTaskManager ().getActiveBrutes ()).clone ()).forEach (bruteForce -> {
52+ ((ArrayList <BruteForce >) ((ArrayList ) vHackOSBot .api .getTaskManager ().getActiveBrutes ()).clone ()).forEach (bruteForce -> {
6453 if (cache .asMap ().containsKey (bruteForce .getIp ())) return ;
6554 if (bruteForce .getState () == BruteForceState .SUCCESS ) {
6655 cache .put (bruteForce .getIp (), "" );
6756 ExploitedTarget etarget = bruteForce .exploit ();
6857 ExploitedTarget .Banking banking = etarget .getBanking ();
6958
7059 if (banking .isBruteForced ()) {
71- long av = banking .getAvaliableMoney ();
72- if (av > 0 && banking .withdraw (NetworkingConfigValues .withdrawPorcentage )) {
73- LOG .info ("Withdrawed " + av + " of " + banking .getTotal () + " from " + etarget .getIp () + "." );
74- } else {
75- LOG .error ("Failed to withdraw from " + etarget .getIp () + "." );
60+ if (banking .canAttack ()) {
61+ long av = banking .getAvaliableMoney ();
62+ if (av > 0 && banking .withdraw (NetworkingConfigValues .withdrawPorcentage )) {
63+ LOG .info ("Withdrawed " + av + " of " + banking .getTotal () + " from " + etarget .getIp () + "." );
64+ } else {
65+ LOG .error ("Failed to withdraw from " + etarget .getIp () + "." );
66+ }
67+ if (eval (etarget )) {
68+ LOG .info ("Removing bruteforce from " + etarget .getIp () + "." );
69+ bruteForce .remove ();
70+ }
7671 }
77- if (eval (etarget )) {
78- LOG .info ("Removing bruteforce from " + etarget .getIp () + "." );
79- bruteForce .remove ();
80- }
81-
8272 } else {
8373 if (banking .startBruteForce ()) {
8474 LOG .info ("Started bruteforce at " + etarget .getIp ());
@@ -99,20 +89,20 @@ public void runService() {
9989 }
10090 });
10191 if (vHackOSBot .api .getStats ().getExploits () > 0 ) {
102- int success = 0 ;
103- int tries = 6 * 3 ;
92+ int success = 0 ;
93+ int tries = 6 * 3 ;
10494 LOG .info ("Starting exploits..." );
105- while (success < 6 && tries > 0 ) {
106- success += scan ();
107- tries --;
108- }
109- LOG .info ("Finished exploits, exploited " + success + " targets in " + tries + " tries." );
95+ while (success < 6 && tries > 0 ) {
96+ success += scan ();
97+ tries --;
98+ }
99+ LOG .info ("Finished exploits, exploited " + success + " targets in " + tries + " tries." );
110100 }
111101 } catch (Exception e ) {
112102 Sentry .capture (e );
103+ LOG .warn ("The networking service has been shutdown due to an error." );
113104 e .printStackTrace ();
114105 networkingService .shutdownNow ();
115- LOG .warn ("The networking service has been shutdown due to an error." );
116106 }
117107 }
118108
@@ -159,4 +149,10 @@ public boolean eval(ExploitedTarget target) {
159149 }
160150 return false ;
161151 }
152+
153+ public class NetworkingServiceFactory implements ThreadFactory {
154+ public Thread newThread (Runnable r ) {
155+ return new Thread (r , "vHackOSBot-NetworkingService" );
156+ }
157+ }
162158}
0 commit comments