Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/alexisvisco/debug
A tiny golang debugging utility based on https://github.com/visionmedia/debug principles.
go get github.com/AlexisVisco/Debug
debug expose some simple functions like Register, Get, Delete to manage debug.
Example http_debug.go
package main
import (
"fmt"
"log"
"net/http"
debug "github.com/AlexisVisco/debug"
)
var httpdeb, _ = debug.Register("http")
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
httpdeb.Log(fmt.Sprintf("%s %s", r.Method, r.URL.String()))
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
Example infinite_debug.go
package main
import (
debug "github.com/AlexisVisco/debug"
"time"
"strconv"
"sync"
)
var fivesec, _ = debug.Register("5 times")
var nivesec, _ = debug.Register("9 times")
var wait sync.WaitGroup
var five = 0
var nine = 0
func main() {
wait.Add(1)
go doEvery(5 * time.Second, func(i time.Time) {
fivesec.Log("5 = " + strconv.Itoa(five))
five++
})
go doEvery(9 * time.Second, func(i time.Time) {
nivesec.Log("9 = " + strconv.Itoa(nine))
nine++
})
wait.Wait()
}
func doEvery(d time.Duration, f func(time.Time)) {
for x := range time.Tick(d) {
f(x)
}
}
The DEBUG environment variable is then used to enable these based on space or comma-delimited names.
The *
character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with DEBUG=connect:bodyParser,connect:compress,connect:session, you may simply do DEBUG=connect:*.
The -
prefix character may be used to exclude a debugger.
Example DEBUG=*,-test
=> atest OK, hello OK, test NOT OK
You can combine with wildcard obviously !
You can set a few environment variables that will change the behavior of the debug logging:
Name | Purpose |
---|---|
DEBUG | Enables/disables specific debugging namespaces. |
DEBUG_HIDE_DATE | Hide date from debug output (non-TTY). |
DEBUG_COLORS | Whether or not to use colors in the debug output. |
DEBUG_HIDE_LATENCY | Hide latency at the end of a tty output. |
Functions:
NewDebug(name string) *Debug
Register(name string) (*Debug, Err)
Get(name string) (*Debug, Err)
Delete(name string) Err
Enable()
Disable()
Methods:
(d *Debug) Log(message string)
(d *Debug) Sprint(message string)
(d *Debug) SetWriter(writer io.Writer, tty bool) *Debug
(d *Debug) SetFdWriter(file *os.File) *Debug
Prototype: NewDebug(name string) *Debug
Description:
Create a debug structure without registering it. Cannot be accessible with Get
.
Generate a random color from 31 to 37 and 91 to 97 as ainsi code.
debug := debug.NewDebug("woaw")
Prototype: Register(name string) (*Debug, Err)
Description:
Create a debug and registering it. Can be accessible with Get
.
NewDebug
is used to create the structure.
Error:
Return an error if name is already in the registry.
debug, err := debug.Create("woaw")
if err {
fmt.Printf("name %s already used !", "woaw")
}
Prototype: Get(name string) (*Debug, Err)
Description:
Get a debug structure from it name.
Error:
Return an error if name is not in the registry.
debug, err := debug.Get("woaw")
if err {
fmt.Printf("name %s has not been created !", "woaw")
}
Prototype: Delete(name string) Err
Description:
Delete a debug structure from the registry.
Error:
Return an error if name is not in the registry.
err := debug.Delete("woaw")
if err {
fmt.Printf("name %s has not been created !", "woaw")
}
Prototype: Enable()
Description:
Enable printing with debug.
debug.Enable()
Prototype: Disable()
Description:
Disable printing with debug.
debug.Disable()
Prototype: (d *Debug) Log(message string
Description:
Print if debug is active the message with the name of the debug and the latency between the last call if it was activated.
woaw, _ := debug.Create("woaw")
woaw.Log("Hola !")
woaw.Log("Hola 2 !")
Prototype: (d *Debug) Sprint(message string)
Description:
Return the full string that should be printed.
woaw, _ := debug.Create("woaw")
str := waw.Sprint("Hola !")
Prototype: (d *Debug) SetWriter(writer io.Writer, tty bool) *Debug
Description:
Set the writer, if it's a terminal set to true the next parameter.
woaw, _ := debug.Create("woaw")
woaw.SetWriter(os.Stdout, true)
Prototype: (d *Debug) SetFdWriter(file *os.File) *Debug
Description:
This function will set the writer and determine if the file.Fd()
is a terminal.
woaw, _ := debug.Create("woaw")
woaw.SetFdWriter(os.Stdout)
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.