Initial commit
This commit is contained in:
commit
404792c2eb
1
validator/.gitignore
vendored
Normal file
1
validator/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
validator
|
61
validator/arp.go
Normal file
61
validator/arp.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ARPTable string = "/proc/net/arp"
|
||||||
|
|
||||||
|
type ARPEntry struct {
|
||||||
|
IP net.IP
|
||||||
|
HWType int
|
||||||
|
Flags int
|
||||||
|
HWAddress net.HardwareAddr
|
||||||
|
Mask string
|
||||||
|
Device string
|
||||||
|
}
|
||||||
|
|
||||||
|
func ARPAnalyze() (ents []ARPEntry, err error) {
|
||||||
|
var content []byte
|
||||||
|
if content, err = ioutil.ReadFile(ARPTable); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, line := range strings.Split(string(content), "\n") {
|
||||||
|
f := strings.Fields(line)
|
||||||
|
if len(f) > 5 {
|
||||||
|
var e ARPEntry
|
||||||
|
|
||||||
|
if _, err := fmt.Sscanf(f[1], "0x%x", &e.HWType); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := fmt.Sscanf(f[2], "0x%x", &e.Flags); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
e.IP = net.ParseIP(f[0])
|
||||||
|
if e.HWAddress, err = net.ParseMAC(f[3]); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
e.Mask = f[4]
|
||||||
|
e.Device = f[5]
|
||||||
|
|
||||||
|
ents = append(ents, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func ARPContainsIP(ents []ARPEntry, ip net.IP) *ARPEntry {
|
||||||
|
for i, e := range ents {
|
||||||
|
if e.IP.Equal(ip) && e.Flags == 2 {
|
||||||
|
return &ents[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
78
validator/index.go
Normal file
78
validator/index.go
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
const indextpl = `<!DOCTYPE html>
|
||||||
|
<html ng-app="FICApp">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Challenge Forensic - Administration</title>
|
||||||
|
<link href="/css/bootstrap.min.css" type="text/css" rel="stylesheet">
|
||||||
|
<link href="/css/glyphicon.css" type="text/css" rel="stylesheet" media="screen">
|
||||||
|
<style>
|
||||||
|
samp.cksum {
|
||||||
|
overflow-x: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
max-width: 20vw;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script src="/js/d3.v3.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body class="bg-light text-dark">
|
||||||
|
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark text-light" style="margin-bottom: 5px;">
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#adminMenu" aria-controls="adminMenu" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<span id="clock" class="navbar-text" ng-controller="CountdownController" ng-cloak>
|
||||||
|
<span ng-show="startIn > 0">
|
||||||
|
Démarrage dans :
|
||||||
|
<span>{{"{{ startIn }}"}}</span>"
|
||||||
|
<span class="point">|</span>
|
||||||
|
</span>
|
||||||
|
<span id="hours">{{"{{ time.hours | time }}"}}</span>
|
||||||
|
<span class="point">:</span>
|
||||||
|
<span id="min">{{"{{ time.minutes | time }}"}}</span>
|
||||||
|
<span class="point">:</span>
|
||||||
|
<span id="sec">{{"{{ time.seconds | time }}"}}</span>
|
||||||
|
</span>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container" ng-controller="DIWEBoxController">
|
||||||
|
<div ng-repeat="box in boxes" class="alert alert-dismissible alert-{{"{{ box.kind }}"}}" ng-cloak>
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<strong ng-if="box.title">{{"{{ box.title }}"}}</strong> {{"{{ box.msg }}"}}
|
||||||
|
<ul ng-if="box.list">
|
||||||
|
<li ng-repeat="i in box.list">{{"{{ i }}"}}</li>
|
||||||
|
</ul>
|
||||||
|
<button class="btn btn-sm btn-success" ng-if="box.yes || box.no" ng-click="box.yes()">Yes</button>
|
||||||
|
<button class="btn btn-sm btn-danger" ng-if="box.yes || box.no" ng-click="box.no()">No</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container" ng-view></div>
|
||||||
|
|
||||||
|
<script src="/js/jquery.min.js"></script>
|
||||||
|
<script src="/js/popper.min.js"></script>
|
||||||
|
<script src="/js/bootstrap.min.js"></script>
|
||||||
|
<script src="/js/angular.min.js"></script>
|
||||||
|
<script src="/js/angular-route.min.js"></script>
|
||||||
|
<script src="/js/angular-sanitize.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
|
func Index(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
|
||||||
|
if indexTmpl, err := template.New("index").Parse(indextpl); err != nil {
|
||||||
|
http.Error(w, "Cannot create template: " + err.Error(), http.StatusInternalServerError)
|
||||||
|
} else if err := indexTmpl.Execute(w, nil); err != nil {
|
||||||
|
http.Error(w, "An error occurs during template execution: " + err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
34
validator/main.go
Normal file
34
validator/main.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var staticDir string
|
||||||
|
var bind = flag.String("bind", ":8081", "Bind port/socket")
|
||||||
|
flag.StringVar(&staticDir, "static", "./static/", "Directory containing static files")
|
||||||
|
flag.StringVar(&ARPTable, "arp", ARPTable, "Path to ARP table")
|
||||||
|
//var tftpdLogs = flag.String("tftpd", "/var/logs/tftpd.log", "Path to TFTPd logs")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
|
// Sanitize options
|
||||||
|
log.Println("Checking paths...")
|
||||||
|
if staticDir, err = filepath.Abs(staticDir); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Registering handlers...")
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/", Index)
|
||||||
|
mux.Handle("/login", loginChecker{students})
|
||||||
|
http.HandleFunc("/", mux.ServeHTTP)
|
||||||
|
|
||||||
|
log.Println("Ready, listening on port", *bind)
|
||||||
|
http.ListenAndServe(*bind, nil)
|
||||||
|
}
|
Reference in New Issue
Block a user