init: initial commit for complete raw root sources of project codebases for dev branch of shikigrid pending push operation for test build of regression version

This commit is contained in:
Anda Toshiki 2024-09-04 23:01:20 -07:00
parent 2d7d249506
commit db6575bcd6
Signed by: andatoshiki
GPG Key ID: 443A8FB634CF898D
34 changed files with 251 additions and 214 deletions

12
.github/FUNDING.yml vendored
View File

@ -1,12 +0,0 @@
# These are supported funding model platforms
github: jayofelony # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon:
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

1
.gitignore vendored
View File

@ -5,4 +5,3 @@ test-unit.pub
build build
id_rsa id_rsa
id_rsa.pub id_rsa.pub
key.json

96
.travis.yml Normal file
View File

@ -0,0 +1,96 @@
sudo: false
os: linux
dist: bionic
language: go
go:
- 1.13.x
env:
global:
- LANG=C
- LC_ALL=C
- OUTPUT="shikigrid"
- VERSION=$(echo ${TRAVIS_BRANCH} | sed "s/\//_/g")
cache:
apt: true
addons:
apt:
packages:
- wget
- p7zip-full
- libpcap-dev
update: true
cross: &cross
before_install:
- wget --show-progress -qcO "qemu.deb" "https://debian.grena.ge/debian/pool/main/q/qemu/qemu-user-static_4.1-1+b4_amd64.deb"
- sudo dpkg -i "qemu.deb"
install:
- sudo builder/arm_builder.sh shikigrid make -e TARGET="${OUTPUT}"
normal: &normal
install:
- make -e TARGET="${OUTPUT}"
end: &end
after_success:
- sudo mv "build/${OUTPUT}" "${OUTPUT}"
- file "${OUTPUT}"
- openssl dgst -sha256 "${OUTPUT}" | tee "${OUTPUT}_${TARGET_OS}_${TARGET_ARCH}_${VERSION}.sha256"
- 7z a "${OUTPUT}_${TARGET_OS}_${TARGET_ARCH}_${VERSION}.zip" "${OUTPUT}" "${OUTPUT}_${TARGET_OS}_${TARGET_ARCH}_${VERSION}.sha256"
matrix:
include:
- name: Linux - amd64
if: tag IS present
arch: amd64
env:
- TARGET_OS=linux
- TARGET_ARCH=amd64
<<: *normal
<<: *end
- name: Linux - aarch64
if: tag IS present
arch: arm64
env:
- TARGET_OS=linux
- TARGET_ARCH=aarch64
<<: *normal
<<: *end
- name: Linux - armhf
if: tag IS present
arch: amd64
language: minimal
env:
- TARGET_OS=linux
- TARGET_ARCH=armhf
<<: *cross
<<: *end
# Tests
# - name: Linux - tests
# if: tag IS blank
# os: linux
# arch: amd64
# install:
# - make deps
# script:
# - make test
# after_success:
# - bash <(curl -s https://codecov.io/bash)
deploy:
provider: releases
api_key:
secure: ljBVe/wVAtOPwCWJPlJ7D1hWGfm6GtHOLgq3wmP4jw/9a2RYV41xJ7g+4R1mm9R8waqtTm9QPDHIKFuN3N9cNs83ZY/fkSJ2WwU3IDV1ZvKPAuucrMSsyOGc08poXj6mmUDs/9LRb100qG81Y5dD+WB6Ep6vWOT7aOi9QNp/WWQ3IDYp5QJIocRHcJhGFH8JO1699mpdNgaukmPHIYK6uVu15TCkYOrvNTD0OTpthN6hIwCBwQ0agFNBbqmwyYsAdUZsjdU7QVOCnPUeXWqoZwq3klFKymsf8f4xra7ou5hsBkL+GFESiGGy0TdU7ZTZjPRKgkpIWtHOURq3WSVtYvCTnKI8h+HdBbKlQeO5g611gUw3CEU5HZxKlG18JTSD5TJNuEAFBVA7X385cVnWbgCLIwLiCDzjKPeVJvyDxyKC1CCtmfYZtanyn18qz/VRtMWrLFRcr5jNrQcloiuJbQzteoxtvbt5c0nM7b1b/AZ4zzGH75MLADxbHw2CThN4R+dxx3lqD0YM3fxbWiWCgZlbrc7GNRq1ilhX0YEDBOVfcdJxYARwrzovrO8bMFGerur4C7HzkpVgE6jfQiZJdXU/5javkLnww6xjDC/jfiMJ7i4OqZ2sgISSVL8Fq4LMqaAumdSHZK/GoJ97PTWUE9sBD7tIGSzHReA8DhpweFI=
skip_cleanup: true
file_glob: true
file:
- shikigrid_*.zip
- shikigrid_*.sha256
on:
tags: true
repo: evilsocket/shikigrid
branches:
only:
- "/^v[0-9]+\\.[0-9]+\\.[0-9]+[A-Za-z0-9]+?$/"

View File

@ -2,7 +2,7 @@ FROM golang:alpine as builder
# ENV GO111MODULE=on # ENV GO111MODULE=on
LABEL maintainer="Anda Toshiki <hello@toshiki.dev>" LABEL maintainer="Simone Margaritelli <evilsocket@gmail.com>"
RUN apk update && apk add --no-cache git RUN apk update && apk add --no-cache git

View File

@ -18,18 +18,18 @@ clean:
restart: restart:
@service shikigrid restart @service shikigrid restart
release_files: clean cross_compile_libpcap_arm64 # cross_compile_libpcap_arm release_files: clean cross_compile_libpcap_x64 cross_compile_libpcap_arm
@mkdir build @mkdir build
@echo building for linux/amd64 ... @echo building for linux/amd64 ...
@CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc GOARCH=amd64 GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go @CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc GOARCH=amd64 GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go
@openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-amd64.sha256" @openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-amd64.sha256"
@zip -j "build/shikigrid-$(VERSION)-amd64.zip" build/shikigrid build/shikigrid-amd64.sha256 > /dev/null @zip -j "build/shikigrid-$(VERSION)-amd64.zip" build/shikigrid build/shikigrid-amd64.sha256 > /dev/null
@rm -rf build/shikigrid build/shikigrid-amd64.sha256 @rm -rf build/shikigrid build/shikigrid-amd64.sha256
@echo building for linux/armv6l ... @echo building for linux/armhf ...
@CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc GOARM=6 GOARCH=arm GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go @CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc GOARM=6 GOARCH=arm GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go
@openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-armv6l.sha256" @openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-armhf.sha256"
@zip -j "build/shikigrid-$(VERSION)-armv6l.zip" build/shikigrid build/shikigrid-armv6l.sha256 > /dev/null @zip -j "build/shikigrid-$(VERSION)-armhf.zip" build/shikigrid build/shikigrid-armhf.sha256 > /dev/null
@rm -rf build/shikigrid build/shikigrid-armv6l.sha256 @rm -rf build/shikigrid build/shikigrid-armhf.sha256
@echo building for linux/aarch64 ... @echo building for linux/aarch64 ...
@CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=arm64 GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go @CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOARCH=arm64 GOOS=linux go build -o build/shikigrid cmd/shikigrid/*.go
@openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-aarch64.sha256" @openssl dgst -sha256 "build/shikigrid" > "build/shikigrid-aarch64.sha256"
@ -37,9 +37,9 @@ release_files: clean cross_compile_libpcap_arm64 # cross_compile_libpcap_arm
@rm -rf build/shikigrid build/shikigrid-aarch64.sha256 @rm -rf build/shikigrid build/shikigrid-aarch64.sha256
@ls -la build @ls -la build
# requires sudo apt-get install bison flex gcc-arm-linux-gnueabi libpcap0.8 libpcap-dev # requires sudo apt-get install bison flex gcc-arm-linux-gnueabihf
cross_compile_libpcap_arm: cross_compile_libpcap_arm:
@echo "Cross-compiling libpcap for armv6l..." @echo "Cross-compiling libpcap for armhf..."
@wget https://www.tcpdump.org/release/libpcap-1.9.1.tar.gz @wget https://www.tcpdump.org/release/libpcap-1.9.1.tar.gz
@tar -zxvf libpcap-1.9.1.tar.gz @tar -zxvf libpcap-1.9.1.tar.gz
@cd libpcap-1.9.1 && \ @cd libpcap-1.9.1 && \
@ -51,18 +51,18 @@ cross_compile_libpcap_arm:
@echo "Clean up..." @echo "Clean up..."
@rm -rf libpcap-1.9.1 libpcap-1.9.1.tar.gz @rm -rf libpcap-1.9.1 libpcap-1.9.1.tar.gz
# requires sudo apt-get install bison flex gcc-aarch64-linux-gnu libpcap0.8 libpcap-dev # requires sudo apt-get install bison flex gcc-x86-64-linux-gnu
cross_compile_libpcap_arm64: cross_compile_libpcap_x64:
@echo "Cross-compiling libpcap for arm64..." @echo "Cross-compiling libpcap for armhf..."
@wget https://www.tcpdump.org/release/libpcap-1.9.1.tar.gz @wget https://www.tcpdump.org/release/libpcap-1.9.1.tar.gz
@tar -zxvf libpcap-1.9.1.tar.gz @tar -zxvf libpcap-1.9.1.tar.gz
@cd libpcap-1.9.1 && \ @cd libpcap-1.9.1 && \
export CC=aarch64-linux-gnu-gcc && \ export CC=x86_64-linux-gnu-gcc && \
./configure --host=aarch64-linux-gnu && \ ./configure --host=x86_64-linux-gnu && \
make make
@echo "Copying cross-compiled libpcap to /usr/lib/x86_64-linux-gnu/" @echo "Copying cross-compiled libpcap to /usr/lib/x86_64-linux-gnu/"
@sudo cp libpcap-1.9.1/libpcap.a /usr/lib/aarch64-linux-gnu/ @sudo cp libpcap-1.9.1/libpcap.a /usr/lib/x86_64-linux-gnu/
@echo "Clean up..." @echo "Clean up..."
@rm -rf libpcap-1.9.1 libpcap-1.9.1.tar.gz @rm -rf libpcap-1.9.1 libpcap-1.9.1.tar.gz
.PHONY: cross_compile_libpcap_arm cross_compile_libpcap_arm64 .PHONY: cross_compile_libpcap_arm cross_compile_libpcap_x64

View File

@ -5,8 +5,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io/ioutil"
"net"
"net/http" "net/http"
"os" "os"
"sync" "sync"
@ -20,7 +19,6 @@ import (
var ( var (
ClientTimeout = 60 ClientTimeout = 60
ClientKeepalive = 30
ClientTokenFile = "/tmp/shikigrid-api-enrollment.json" ClientTokenFile = "/tmp/shikigrid-api-enrollment.json"
Endpoint = "" Endpoint = ""
) )
@ -32,34 +30,20 @@ var (
type Client struct { type Client struct {
sync.Mutex sync.Mutex
cli *http.Client cli *http.Client
keys *crypto.KeyPair keys *crypto.KeyPair
token string token string
tokenAt time.Time tokenAt time.Time
data map[string]interface{} data map[string]interface{}
hostname string
} }
func NewClient(keys *crypto.KeyPair, endpoint string, hostname string) *Client { func NewClient(keys *crypto.KeyPair, endpoint string) *Client {
t := &http.Transport{
Dial: (&net.Dialer{
Timeout: time.Duration(ClientTimeout) * time.Second,
KeepAlive: time.Duration(ClientKeepalive) * time.Second,
}).Dial,
TLSHandshakeTimeout: time.Duration(ClientTimeout) * time.Second,
ResponseHeaderTimeout: time.Duration(ClientTimeout) * time.Second,
ExpectContinueTimeout: 4 * time.Second,
}
cli := &Client{ cli := &Client{
cli: &http.Client{ cli: &http.Client{
Transport: t, Timeout: time.Duration(ClientTimeout) * time.Second,
Timeout: time.Duration(ClientTimeout) * time.Second,
}, },
keys: keys, keys: keys,
data: make(map[string]interface{}), data: make(map[string]interface{}),
hostname: hostname,
} }
Endpoint = endpoint Endpoint = endpoint
@ -68,7 +52,7 @@ func NewClient(keys *crypto.KeyPair, endpoint string, hostname string) *Client {
if time.Since(info.ModTime()) < models.TokenTTL { if time.Since(info.ModTime()) < models.TokenTTL {
log.Debug("loading token from %s ...", ClientTokenFile) log.Debug("loading token from %s ...", ClientTokenFile)
var data map[string]interface{} var data map[string]interface{}
if raw, err := os.ReadFile(ClientTokenFile); err == nil { if raw, err := ioutil.ReadFile(ClientTokenFile); err == nil {
if err := json.Unmarshal(raw, &data); err == nil { if err := json.Unmarshal(raw, &data); err == nil {
cli.token = data["token"].(string) cli.token = data["token"].(string)
cli.tokenAt = info.ModTime() cli.tokenAt = info.ModTime()
@ -88,12 +72,7 @@ func NewClient(keys *crypto.KeyPair, endpoint string, hostname string) *Client {
} }
func (c *Client) enroll() error { func (c *Client) enroll() error {
identity := fmt.Sprintf("%s@%s", utils.Hostname(), c.keys.FingerprintHex)
hostname := c.hostname
if hostname == "" {
hostname = utils.Hostname()
}
identity := fmt.Sprintf("%s@%s", hostname, c.keys.FingerprintHex)
log.Debug("refreshing api token as %s ...", identity) log.Debug("refreshing api token as %s ...", identity)
@ -125,7 +104,7 @@ func (c *Client) enroll() error {
if raw, err := json.Marshal(obj); err == nil { if raw, err := json.Marshal(obj); err == nil {
log.Debug("saving token to %s ...", ClientTokenFile) log.Debug("saving token to %s ...", ClientTokenFile)
if err = os.WriteFile(ClientTokenFile, raw, 0644); err != nil { if err = ioutil.WriteFile(ClientTokenFile, raw, 0644); err != nil {
log.Warning("error saving token to %s: %v", ClientTokenFile, err) log.Warning("error saving token to %s: %v", ClientTokenFile, err)
} }
} else { } else {
@ -172,20 +151,19 @@ func (c *Client) request(method string, path string, data interface{}, auth bool
if err != nil { if err != nil {
return nil, err return nil, err
} }
body, err := io.ReadAll(res.Body) body, err := ioutil.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var obj map[string]interface{} var obj map[string]interface{}
if err = json.Unmarshal(body, &obj); err != nil { if err = json.Unmarshal(body, &obj); err != nil {
log.Debug(fmt.Sprintf("Error Unmarshalling json body from request: %v", body))
return nil, err return nil, err
} }
if res.StatusCode == 401 { if res.StatusCode == 401 {
if err := c.enroll(); err != nil { if err := c.enroll(); err != nil {
log.Warning("error token expired during operation: %v", err) log.Warning("error token expired failed to re-enroll: %v", err)
return nil, err return nil, err
} }
log.Warning("token expired, re-enroll success") log.Warning("token expired, re-enroll success")

View File

@ -3,20 +3,20 @@ package api
import ( import (
"encoding/json" "encoding/json"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"io" "io/ioutil"
"net/http" "net/http"
) )
// PeerGetData GET /api/v1/data // GET /api/v1/data
func (api *API) PeerGetData(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetData(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, api.Client.Data()) JSON(w, http.StatusOK, api.Client.Data())
} }
// PeerSetData POST /api/v1/data // POST /api/v1/data
func (api *API) PeerSetData(w http.ResponseWriter, r *http.Request) { func (api *API) PeerSetData(w http.ResponseWriter, r *http.Request) {
var newData map[string]interface{} var newData map[string]interface{}
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)
return return

View File

@ -8,7 +8,7 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/andatoshiki/shikigrid/crypto" "github.com/andatoshiki/shikigrid/crypto"
"github.com/andatoshiki/shikigrid/models" "github.com/andatoshiki/shikigrid/models"
"io" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
) )
@ -18,7 +18,7 @@ var (
ErrSenderNotFound = errors.New("sender not found") ErrSenderNotFound = errors.New("sender not found")
) )
// PeerGetInbox /api/v1/inbox/ // /api/v1/inbox/
func (api *API) PeerGetInbox(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetInbox(w http.ResponseWriter, r *http.Request) {
page, err := pageNum(r) page, err := pageNum(r)
if err != nil { if err != nil {
@ -175,7 +175,7 @@ func (api *API) SendMessage(fingerprint string, cleartext []byte) (int, error) {
// POST /api/v1/unit/<fingerprint>/inbox // POST /api/v1/unit/<fingerprint>/inbox
func (api *API) PeerSendMessageTo(w http.ResponseWriter, r *http.Request) { func (api *API) PeerSendMessageTo(w http.ResponseWriter, r *http.Request) {
cleartextMessage, err := io.ReadAll(r.Body) cleartextMessage, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
log.Error("error reading request body: %v", err) log.Error("error reading request body: %v", err)
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)

View File

@ -2,16 +2,15 @@ package api
import ( import (
"encoding/json" "encoding/json"
"io"
"net/http"
"sort"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/andatoshiki/shikigrid/mesh" "github.com/andatoshiki/shikigrid/mesh"
"io/ioutil"
"net/http"
"sort"
) )
// PeerGetPeers GET /api/v1/mesh/peers // GET /api/v1/mesh/peers
func (api *API) PeerGetPeers(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetPeers(w http.ResponseWriter, r *http.Request) {
peers := make([]*mesh.Peer, 0) peers := make([]*mesh.Peer, 0)
mesh.Peers.Range(func(key, value interface{}) bool { mesh.Peers.Range(func(key, value interface{}) bool {
@ -27,7 +26,7 @@ func (api *API) PeerGetPeers(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, peers) JSON(w, http.StatusOK, peers)
} }
// PeerGetMemory GET /api/v1/mesh/memory // GET /api/v1/mesh/memory
func (api *API) PeerGetMemory(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetMemory(w http.ResponseWriter, r *http.Request) {
peers := api.Mesh.Memory() peers := api.Mesh.Memory()
// higher number of encounters first // higher number of encounters first
@ -37,7 +36,7 @@ func (api *API) PeerGetMemory(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, peers) JSON(w, http.StatusOK, peers)
} }
// PeerGetMemoryOf GET /api/v1/mesh/memory/<fingerprint> // GET /api/v1/mesh/memory/<fingerprint>
func (api *API) PeerGetMemoryOf(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetMemoryOf(w http.ResponseWriter, r *http.Request) {
fingerprint := chi.URLParam(r, "fingerprint") fingerprint := chi.URLParam(r, "fingerprint")
peer := api.Mesh.MemoryOf(fingerprint) peer := api.Mesh.MemoryOf(fingerprint)
@ -48,7 +47,7 @@ func (api *API) PeerGetMemoryOf(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, peer) JSON(w, http.StatusOK, peer)
} }
// PeerSetSignaling GET /api/v1/mesh/<status> // GET /api/v1/mesh/<status>
func (api *API) PeerSetSignaling(w http.ResponseWriter, r *http.Request) { func (api *API) PeerSetSignaling(w http.ResponseWriter, r *http.Request) {
status := chi.URLParam(r, "status") status := chi.URLParam(r, "status")
@ -66,24 +65,16 @@ func (api *API) PeerSetSignaling(w http.ResponseWriter, r *http.Request) {
}) })
} }
// PeerGetMeshData GET /api/v1/mesh/data // GET /api/v1/mesh/data
func (api *API) PeerGetMeshData(w http.ResponseWriter, r *http.Request) { func (api *API) PeerGetMeshData(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, api.Peer.Data()) JSON(w, http.StatusOK, api.Peer.Data())
} }
// PeerSetMeshData POST /api/v1/mesh/data // POST /api/v1/mesh/data
func (api *API) PeerSetMeshData(w http.ResponseWriter, r *http.Request) { func (api *API) PeerSetMeshData(w http.ResponseWriter, r *http.Request) {
var newData map[string]interface{} var newData map[string]interface{}
if api.Peer.ForceDisabled == true { body, err := ioutil.ReadAll(r.Body)
api.Peer.Advertise(false)
JSON(w, http.StatusOK, map[string]interface{}{
"success": true, // this should be changed later when shikigotchi can handle shikigrid being force advertise disabled
})
return
}
body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)
return return

View File

@ -3,15 +3,15 @@ package api
import ( import (
"encoding/json" "encoding/json"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"io" "io/ioutil"
"net/http" "net/http"
) )
// PeerReportAP POST /api/v1/report/ap // POST /api/v1/report/ap
func (api *API) PeerReportAP(w http.ResponseWriter, r *http.Request) { func (api *API) PeerReportAP(w http.ResponseWriter, r *http.Request) {
var report apReport var report apReport
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)
return return

View File

@ -20,13 +20,13 @@ type API struct {
Client *Client Client *Client
} }
func Setup(keys *crypto.KeyPair, peer *mesh.Peer, router *mesh.Router, Endpoint string, Hostname string) (err error, api *API) { func Setup(keys *crypto.KeyPair, peer *mesh.Peer, router *mesh.Router, Endpoint string) (err error, api *API) {
api = &API{ api = &API{
Router: chi.NewRouter(), Router: chi.NewRouter(),
Keys: keys, Keys: keys,
Peer: peer, Peer: peer,
Mesh: router, Mesh: router,
Client: NewClient(keys, Endpoint, Hostname), Client: NewClient(keys, Endpoint),
} }
api.Router.Use(CORS) api.Router.Use(CORS)

View File

@ -4,14 +4,14 @@ import (
"encoding/json" "encoding/json"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"github.com/andatoshiki/shikigrid/models" "github.com/andatoshiki/shikigrid/models"
"io" "io/ioutil"
"net/http" "net/http"
) )
func (api *API) readEnrollment(w http.ResponseWriter, r *http.Request) (error, models.EnrollmentRequest) { func (api *API) readEnrollment(w http.ResponseWriter, r *http.Request) (error, models.EnrollmentRequest) {
var enroll models.EnrollmentRequest var enroll models.EnrollmentRequest
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)
return err, enroll return err, enroll

View File

@ -8,7 +8,7 @@ import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/andatoshiki/shikigrid/crypto" "github.com/andatoshiki/shikigrid/crypto"
"github.com/andatoshiki/shikigrid/models" "github.com/andatoshiki/shikigrid/models"
"io" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@ -148,7 +148,7 @@ func (api *API) SendMessageTo(w http.ResponseWriter, r *http.Request) {
// read the message and signature from the source unit // read the message and signature from the source unit
client := clientIP(r) client := clientIP(r)
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, err) ERROR(w, http.StatusUnprocessableEntity, err)
return return

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"github.com/andatoshiki/shikigrid/models" "github.com/andatoshiki/shikigrid/models"
"io" "io/ioutil"
"net" "net"
"net/http" "net/http"
) )
@ -50,7 +50,7 @@ func (api *API) UnitReportAP(w http.ResponseWriter, r *http.Request) {
} }
client := clientIP(r) client := clientIP(r)
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, ErrEmpty) ERROR(w, http.StatusUnprocessableEntity, ErrEmpty)
return return
@ -81,7 +81,7 @@ func (api *API) UnitReportMultipleAP(w http.ResponseWriter, r *http.Request) {
} }
client := clientIP(r) client := clientIP(r)
body, err := io.ReadAll(r.Body) body, err := ioutil.ReadAll(r.Body)
if err != nil { if err != nil {
ERROR(w, http.StatusUnprocessableEntity, ErrEmpty) ERROR(w, http.StatusUnprocessableEntity, ErrEmpty)
return return

View File

@ -5,6 +5,7 @@ import (
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"github.com/evilsocket/islazy/tui" "github.com/evilsocket/islazy/tui"
"github.com/andatoshiki/shikigrid/api" "github.com/andatoshiki/shikigrid/api"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@ -20,10 +21,7 @@ func clearScreen() {
} }
cmd := exec.Command(what[0], what[1:]...) cmd := exec.Command(what[0], what[1:]...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
err := cmd.Run() cmd.Run()
if err != nil {
return
}
} }
func showInbox(server *api.API, box map[string]interface{}) { func showInbox(server *api.API, box map[string]interface{}) {
@ -100,7 +98,7 @@ func showMessage(msg map[string]interface{}) {
if output == "" { if output == "" {
fmt.Printf("%s\n", msg["data"]) fmt.Printf("%s\n", msg["data"])
fmt.Println() fmt.Println()
} else if err := os.WriteFile(output, msg["data"].([]byte), os.ModePerm); err != nil { } else if err := ioutil.WriteFile(output, msg["data"].([]byte), os.ModePerm); err != nil {
log.Fatal("error writing to %s: %v", output, err) log.Fatal("error writing to %s: %v", output, err)
} else { } else {
log.Info("%s written", output) log.Info("%s written", output)
@ -116,7 +114,7 @@ func sendMessage() {
log.Fatal("-message can not be empty") log.Fatal("-message can not be empty")
} else if message[0] == '@' { } else if message[0] == '@' {
log.Info("reading %s ...", message[1:]) log.Info("reading %s ...", message[1:])
if raw, err = os.ReadFile(message[1:]); err != nil { if raw, err = ioutil.ReadFile(message[1:]); err != nil {
log.Fatal("error reading %s: %v", message[1:], err) log.Fatal("error reading %s: %v", message[1:], err)
} }
} else { } else {

View File

@ -86,11 +86,12 @@ func waitForKeys() {
func setupMesh() { func setupMesh() {
var err error var err error
peer = mesh.MakeLocalPeer(utils.Hostname(), keys, advertise)
if !advertise { if advertise == false {
return //this probably doesn't work return //this probably doesnt work
} }
peer = mesh.MakeLocalPeer(utils.Hostname(), keys)
if err = peer.StartAdvertising(iface); err != nil { if err = peer.StartAdvertising(iface); err != nil {
log.Fatal("error while starting signaling: %v", err) log.Fatal("error while starting signaling: %v", err)
} }
@ -130,7 +131,7 @@ func setupMode() string {
// for inbox actions, set the keys to the default path if empty // for inbox actions, set the keys to the default path if empty
if (whoami || inbox) && keysPath == "" { if (whoami || inbox) && keysPath == "" {
keysPath = "/etc/shikigotchi/" keysPath = "/etc/pwnagotchi/"
} }
// generate keypair // generate keypair
@ -158,30 +159,35 @@ func setupMode() string {
log.Info("shikigrid v%s starting in %s mode ...", version.Version, mode) log.Info("shikigrid v%s starting in %s mode ...", version.Version, mode)
// wait for keys to be generated if mode == "peer" {
if wait { // wait for keys to be generated
waitForKeys() if wait {
} waitForKeys()
// load the keys
if keys, err = crypto.Load(keysPath); err != nil {
log.Fatal("error while loading keys from %s: %v", keysPath, err)
}
// print identity and exit
if whoami {
if Endpoint == "https://grid-api.toshiki.dev/api/v1" {
log.Info("https://grid.toshiki.dev/search/%s", keys.FingerprintHex)
} else {
log.Info("https://pwnagotchi.ai/pwnfile/#!%s", keys.FingerprintHex)
} }
os.Exit(0) // load the keys
} if keys, err = crypto.Load(keysPath); err != nil {
// only start mesh signaling if this is not an inbox action log.Fatal("error while loading keys from %s: %v", keysPath, err)
if !inbox { }
setupMesh() // print identity and exit
if whoami {
if Endpoint == "https://grid-api.toshiki.dev/api/v1" {
log.Info("https://toshiki.dev/search/%s", keys.FingerprintHex)
} else {
log.Info("https://pwnagotchi.ai/pwnfile/#!%s", keys.FingerprintHex)
}
os.Exit(0)
}
// only start mesh signaling if this is not an inbox action
if !inbox {
setupMesh()
}
} else if mode == "server" {
// server side we just need to setup the database connection
setupDB()
} }
// set up the proper routes for either server or peer mode // setup the proper routes for either server or peer mode
err, server = api.Setup(keys, peer, router, Endpoint, Hostname) err, server = api.Setup(keys, peer, router, Endpoint)
if err != nil { if err != nil {
log.Fatal("%v", err) log.Fatal("%v", err)
} }

View File

@ -29,7 +29,7 @@ var (
id = 0 id = 0
address = "0.0.0.0:8666" address = "0.0.0.0:8666"
env = ".env" env = ".env"
iface = "wlan0mon" iface = "mon0"
keysPath = "" keysPath = ""
peersPath = "/root/peers" peersPath = "/root/peers"
keys = (*crypto.KeyPair)(nil) keys = (*crypto.KeyPair)(nil)
@ -40,7 +40,6 @@ var (
memProfile = "" memProfile = ""
Endpoint = "https://grid-api.toshiki.dev/api/v1" Endpoint = "https://grid-api.toshiki.dev/api/v1"
advertise = true advertise = true
Hostname = ""
) )
func init() { func init() {
@ -79,5 +78,4 @@ func init() {
flag.StringVar(&Endpoint, "endpoint", Endpoint, "Pass which endpoint shikigrid should be using.") flag.StringVar(&Endpoint, "endpoint", Endpoint, "Pass which endpoint shikigrid should be using.")
flag.BoolVar(&advertise, "advertise", advertise, "Advertise?") flag.BoolVar(&advertise, "advertise", advertise, "Advertise?")
flag.StringVar(&Hostname, "hostname", Hostname, "Pass hostname to shikigrid, makes it so it wont read os.hostname()")
} }

View File

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"github.com/evilsocket/islazy/fs" "github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -137,7 +138,7 @@ func (pair *KeyPair) Save() (err error) {
}, },
) )
if err = os.WriteFile(pair.PrivatePath, pair.PrivatePEM, os.ModePerm); err != nil { if err = ioutil.WriteFile(pair.PrivatePath, pair.PrivatePEM, os.ModePerm); err != nil {
return return
} }
@ -147,7 +148,7 @@ func (pair *KeyPair) Save() (err error) {
return err return err
} }
err = os.WriteFile(pair.PublicPath, pair.PublicPEM, os.ModePerm) err = ioutil.WriteFile(pair.PublicPath, pair.PublicPEM, os.ModePerm)
log.Debug("%s created", pair.PublicPath) log.Debug("%s created", pair.PublicPath)
return return
@ -155,7 +156,7 @@ func (pair *KeyPair) Save() (err error) {
func (pair *KeyPair) Load() (err error) { func (pair *KeyPair) Load() (err error) {
log.Debug("reading %s ...", pair.PrivatePath) log.Debug("reading %s ...", pair.PrivatePath)
if pair.PrivatePEM, err = os.ReadFile(pair.PrivatePath); err != nil { if pair.PrivatePEM, err = ioutil.ReadFile(pair.PrivatePath); err != nil {
return return
} }

9
go.mod
View File

@ -5,17 +5,16 @@ go 1.21
require ( require (
github.com/biezhi/gorm-paginator/pagination v0.0.0-20190124091837-7a5c8ed20334 github.com/biezhi/gorm-paginator/pagination v0.0.0-20190124091837-7a5c8ed20334
github.com/evilsocket/islazy v1.11.0 github.com/evilsocket/islazy v1.11.0
github.com/go-chi/chi/v5 v5.1.0 github.com/go-chi/chi/v5 v5.0.11
github.com/go-chi/cors v1.2.1 github.com/go-chi/cors v1.2.1
github.com/golang-jwt/jwt/v5 v5.2.1 github.com/golang-jwt/jwt/v5 v5.2.0
github.com/gopacket/gopacket v1.2.0 github.com/gopacket/gopacket v1.2.0
github.com/jinzhu/gorm v1.9.16 github.com/jinzhu/gorm v1.9.16
github.com/joho/godotenv v1.5.1 github.com/joho/godotenv v1.5.1
) )
require ( require (
filippo.io/edwards25519 v1.1.0 // indirect github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect
golang.org/x/sys v0.22.0 // indirect golang.org/x/sys v0.15.0 // indirect
) )

25
go.sum
View File

@ -1,5 +1,3 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/biezhi/gorm-paginator/pagination v0.0.0-20190124091837-7a5c8ed20334 h1:ptFjQ4+vPGZDiNmBuKUetQoREFiPz/WB29CfQfdfeKc= github.com/biezhi/gorm-paginator/pagination v0.0.0-20190124091837-7a5c8ed20334 h1:ptFjQ4+vPGZDiNmBuKUetQoREFiPz/WB29CfQfdfeKc=
@ -10,17 +8,15 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DP
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0= github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0=
github.com/evilsocket/islazy v1.11.0/go.mod h1:muYH4x5MB5YRdkxnrOtrXLIBX6LySj1uFIqys94LKdo= github.com/evilsocket/islazy v1.11.0/go.mod h1:muYH4x5MB5YRdkxnrOtrXLIBX6LySj1uFIqys94LKdo=
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s= github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4= github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58= github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/gopacket/gopacket v1.2.0 h1:eXbzFad7f73P1n2EJHQlsKuvIMJjVXK5tXoSca78I3A= github.com/gopacket/gopacket v1.2.0 h1:eXbzFad7f73P1n2EJHQlsKuvIMJjVXK5tXoSca78I3A=
@ -48,11 +44,12 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -9,7 +9,7 @@ import (
) )
func ChannelHopping(iface string, chanList string, allChannels []int, hopPeriod int) { func ChannelHopping(iface string, chanList string, allChannels []int, hopPeriod int) {
var channels []int channels := []int{}
for _, s := range str.Comma(chanList) { for _, s := range str.Comma(chanList) {
if ch, err := strconv.Atoi(s); err != nil { if ch, err := strconv.Atoi(s); err != nil {
log.Fatal("%v", err) log.Fatal("%v", err)

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
) )
var chanParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9.]+)\s+GHz.*$`) var chanParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9\.]+)\s+GHz.*$`)
func ActivateInterface(name string) error { func ActivateInterface(name string) error {
if out, err := utils.Exec("ifconfig", []string{name, "up"}); err != nil { if out, err := utils.Exec("ifconfig", []string{name, "up"}); err != nil {
@ -36,7 +36,7 @@ func SupportedChannels(iface string) ([]int, error) {
return nil, err return nil, err
} }
var channels []int channels := []int{}
scanner := bufio.NewScanner(strings.NewReader(out)) scanner := bufio.NewScanner(strings.NewReader(out))
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/evilsocket/islazy/fs" "github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -37,7 +38,7 @@ func MemoryFromPath(path string) (err error, mem *Memory) {
err = fs.Glob(path, "*.json", func(fileName string) error { err = fs.Glob(path, "*.json", func(fileName string) error {
log.Debug("loading %s ...", fileName) log.Debug("loading %s ...", fileName)
data, err := os.ReadFile(fileName) data, err := ioutil.ReadFile(fileName)
if err != nil { if err != nil {
log.Error("error loading %s: %v", fileName, err) log.Error("error loading %s: %v", fileName, err)
return nil return nil
@ -114,7 +115,7 @@ func (mem *Memory) Track(fingerprint string, peer *Peer) error {
fileName := path.Join(mem.path, fmt.Sprintf("%s.json", fingerprint)) fileName := path.Join(mem.path, fmt.Sprintf("%s.json", fingerprint))
if data, err := json.Marshal(peer); err != nil { if data, err := json.Marshal(peer); err != nil {
return err return err
} else if err := os.WriteFile(fileName, data, os.ModePerm); err != nil { } else if err := ioutil.WriteFile(fileName, data, os.ModePerm); err != nil {
return err return err
} }

View File

@ -11,7 +11,7 @@ import (
) )
const ( const (
// ErrIfaceNotUp Ugly, but gopacket folks are not exporting pcap errors, so ... // Ugly, but gopacket folks are not exporting pcap errors, so ...
// ref. https://github.com/gopacket/gopacket/blob/96986c90e3e5c7e01deed713ff8058e357c0c047/pcap/pcap.go#L281 // ref. https://github.com/gopacket/gopacket/blob/96986c90e3e5c7e01deed713ff8058e357c0c047/pcap/pcap.go#L281
ErrIfaceNotUp = "Interface Not Up" ErrIfaceNotUp = "Interface Not Up"
) )

View File

@ -6,17 +6,16 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"regexp"
"strings"
"sync"
"time"
"github.com/evilsocket/islazy/log" "github.com/evilsocket/islazy/log"
"github.com/gopacket/gopacket/layers" "github.com/gopacket/gopacket/layers"
"github.com/andatoshiki/shikigrid/crypto" "github.com/andatoshiki/shikigrid/crypto"
"github.com/andatoshiki/shikigrid/version" "github.com/andatoshiki/shikigrid/version"
"github.com/andatoshiki/shikigrid/wifi" "github.com/andatoshiki/shikigrid/wifi"
"net"
"regexp"
"strings"
"sync"
"time"
) )
var ( var (
@ -43,29 +42,23 @@ type Peer struct {
AdvData sync.Map AdvData sync.Map
AdvPeriod int AdvPeriod int
advEnabled bool advEnabled bool
ForceDisabled bool mux *PacketMuxer
stop chan struct{}
mux *PacketMuxer
stop chan struct{}
} }
func MakeLocalPeer(name string, keys *crypto.KeyPair, advertise bool) *Peer { func MakeLocalPeer(name string, keys *crypto.KeyPair) *Peer {
now := time.Now() now := time.Now()
peer := &Peer{ peer := &Peer{
DetectedAt: now, DetectedAt: now,
SeenAt: now, SeenAt: now,
PrevSeenAt: now, PrevSeenAt: now,
SessionID: make([]byte, 6), SessionID: make([]byte, 6),
Keys: keys, Keys: keys,
AdvData: sync.Map{}, AdvData: sync.Map{},
AdvPeriod: SignalingPeriod, AdvPeriod: SignalingPeriod,
stop: make(chan struct{}), stop: make(chan struct{}),
advEnabled: false, advEnabled: false,
ForceDisabled: false,
}
if !advertise {
peer.ForceDisabled = true
} }
if _, err := rand.Read(peer.SessionID); err != nil { if _, err := rand.Read(peer.SessionID); err != nil {
@ -216,7 +209,7 @@ func (peer *Peer) Update(radio *layers.RadioTap, dot11 *layers.Dot11, adv map[st
} }
// the signature is SIGN(advertisement), so we need to remove the signature field and convert back to json. // the signature is SIGN(advertisement), so we need to remove the signature field and convert back to json.
// NOTE: fortunately, keys will always be sorted, so we don't have to do anything in order to guarantee signature // NOTE: fortunately, keys will be always sorted, so we don't have to do anything in order to guarantee signature
// consistency (https://stackoverflow.com/questions/18668652/how-to-produce-json-with-sorted-keys-in-go) // consistency (https://stackoverflow.com/questions/18668652/how-to-produce-json-with-sorted-keys-in-go)
signedMap := adv signedMap := adv
delete(signedMap, "signature") delete(signedMap, "signature")
@ -272,9 +265,6 @@ func (peer *Peer) InactiveFor() float64 {
} }
func (peer *Peer) SetData(adv map[string]interface{}) { func (peer *Peer) SetData(adv map[string]interface{}) {
if peer == nil {
return
}
peer.Lock() peer.Lock()
defer peer.Unlock() defer peer.Unlock()

View File

@ -81,7 +81,7 @@ func (router *Router) peersPruner() {
log.Debug("peers pruner started with a %s period", period) log.Debug("peers pruner started with a %s period", period)
for range tick.C { for _ = range tick.C {
stale := map[string]*Peer{} stale := map[string]*Peer{}
Peers.Range(func(key, value interface{}) bool { Peers.Range(func(key, value interface{}) bool {

View File

@ -3,28 +3,25 @@
VERSION_FILE=$(dirname "${BASH_SOURCE[0]}")/version/ver.go VERSION_FILE=$(dirname "${BASH_SOURCE[0]}")/version/ver.go
echo "version file is $VERSION_FILE" echo "version file is $VERSION_FILE"
CURRENT_VERSION=$(cat "$VERSION_FILE" | grep Version | cut -d '"' -f 2) CURRENT_VERSION=$(cat $VERSION_FILE | grep Version | cut -d '"' -f 2)
TO_UPDATE=( TO_UPDATE=(
# shellcheck disable=SC2206
$VERSION_FILE $VERSION_FILE
) )
echo -n "current version is $CURRENT_VERSION, select new version: " echo -n "current version is $CURRENT_VERSION, select new version: "
read NEW_VERSION read NEW_VERSION
# shellcheck disable=SC2028
echo "creating version $NEW_VERSION ...\n" echo "creating version $NEW_VERSION ...\n"
for file in "${TO_UPDATE[@]}"; do for file in "${TO_UPDATE[@]}"; do
echo "patching $file ..." echo "patching $file ..."
sed -i.bak "s/$CURRENT_VERSION/$NEW_VERSION/g" "$file" sed -i.bak "s/$CURRENT_VERSION/$NEW_VERSION/g" "$file"
rm -rf "$file.bak" rm -rf "$file.bak"
git add "$file" git add $file
done done
git commit -m "releasing v$NEW_VERSION" git commit -m "releasing v$NEW_VERSION"
git push git push
git tag -a v"$NEW_VERSION" -m "release v$NEW_VERSION" git tag -a v$NEW_VERSION -m "release v$NEW_VERSION"
# shellcheck disable=SC2086
git push origin v$NEW_VERSION git push origin v$NEW_VERSION
echo echo

View File

@ -1,11 +1,12 @@
[Unit] [Unit]
Description=shikigrid peer service Description=shikigrid peer service
Documentation=https://shikigotchi.org/ Documentation=https://shikigotchi.toshiki.dev/
Wants=network.target Wants=network.target
After=network.target After=network.target
[Service] [Service]
Type=simple Type=simple
PermissionsStartOnly=true
ExecStart=/usr/local/bin/shikigrid -log /var/log/shikigrid.log -peers /root/peers -address 127.0.0.1:8666 ExecStart=/usr/local/bin/shikigrid -log /var/log/shikigrid.log -peers /root/peers -address 127.0.0.1:8666
Restart=always Restart=always
RestartSec=30 RestartSec=30

View File

@ -1,11 +1,12 @@
[Unit] [Unit]
Description=shikigrid api service Description=shikigrid api service
Documentation=https://shikigotchi.org/ Documentation=https://shikigotchi.toshiki.dev/
Wants=network.target Wants=network.target
After=network.target After=network.target
[Service] [Service]
Type=simple Type=simple
PermissionsStartOnly=true
ExecStart=/usr/local/bin/shikigrid -log /var/log/shikigrid.log -env /etc/shikigrid/shikigrid.conf -address 127.0.0.1:8666 ExecStart=/usr/local/bin/shikigrid -log /var/log/shikigrid.log -env /etc/shikigrid/shikigrid.conf -address 127.0.0.1:8666
Restart=always Restart=always
RestartSec=30 RestartSec=30

View File

@ -1,5 +1,5 @@
package version package version
const ( const (
Version = "0.0.1" Version = "1.10.7"
) )

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io/ioutil"
) )
func Compress(data []byte) (bool, []byte, error) { func Compress(data []byte) (bool, []byte, error) {
@ -33,12 +33,7 @@ func Decompress(data []byte) ([]byte, error) {
if zr, err := gzip.NewReader(bytes.NewBuffer(data)); err != nil { if zr, err := gzip.NewReader(bytes.NewBuffer(data)); err != nil {
return nil, fmt.Errorf("error initializing payload decompression: %v", err) return nil, fmt.Errorf("error initializing payload decompression: %v", err)
} else { } else {
defer func(zr *gzip.Reader) { defer zr.Close()
err := zr.Close() return ioutil.ReadAll(zr)
if err != nil {
}
}(zr)
return io.ReadAll(zr)
} }
} }

View File

@ -23,7 +23,7 @@ func Freq2Chan(freq int) int {
return ((freq - 2412) / 5) + 1 return ((freq - 2412) / 5) + 1
} else if freq == 2484 { } else if freq == 2484 {
return 14 return 14
} else if freq >= 5035 && freq <= 5885 { } else if freq >= 5035 && freq <= 5865 {
return ((freq - 5035) / 5) + 7 return ((freq - 5035) / 5) + 7
} }
return 0 return 0
@ -34,8 +34,9 @@ func Chan2Freq(channel int) int {
return ((channel - 1) * 5) + 2412 return ((channel - 1) * 5) + 2412
} else if channel == 14 { } else if channel == 14 {
return 2484 return 2484
} else if channel <= 177 { } else if channel <= 173 {
return ((channel - 7) * 5) + 5035 return ((channel - 7) * 5) + 5035
} }
return 0 return 0
} }