Recent Posts
-
May 10, 2022
Perl和python的ssh client例子
#!/usr/bin/perluse Net::SSH::Perl;my %params;$params{"debug"} = true;my $ssh = Net::SSH::Perl->new("192.168.1.1", %params);$ssh->login("admin", "admin");my($stdout, $stderr, $exit) = $ssh->cmd("df -h");print $stdout;import paramikoparamik...
-
April 26, 2022
Golang的嵌入式脚本starlark
类似python的语法主要的文档:https://github.com/google/starlark-go https://github.com/google/starlark-go/blob/master/doc/spec.md https://pkg.go.dev/go.starlark.net/starlark例子在telegraf里面有:https://github.com/influxdata/telegraf/tree/master/plugins/processors/...
-
April 18, 2022
Tcp拥塞控制算法设置相关
运行时修改系统默认tcp拥塞控制算法/proc/sys/net/ipv4/tcp_available_congestion_controlecho bbr > /proc/sys/net/ipv4/tcp_congestion_control内核里面创建tcp socket时初始化默认的拥塞控制算法tcp_init_sock tcp_assign_congestion_control(sk);内核修改某个socket的拥塞控制算法的接口do_tcp_setsockopt(TCP_...
-
April 15, 2022
Golang程序随机出现cpu 100%的bug
https://github.com/golang/go/issues/51654 v1.16.7 ~ v1.18 都会出现这个bug。线上的机器遇到的好像就是这个问题,golang的应用一天中随机出现几次cpu 100%的问题,过几秒可能就恢复正常.看描述好像说是在不同的goroutine里面修改同一个Timer场景会导致这个问题。用perf采样,cpu利用率调用栈大概是这样的。 32.70% [.] runtime.stealWork 12.51% [...
-
April 15, 2022
Golang程序加载tls证书的代码
func loadTLSConfig(c *ServiceConfig) *tls.Config { cfg := &tls.Config{} if len(c.CertFile) > 0 && len(c.KeyFile) > 0 { cert, err := tls.LoadX509KeyPair(c.CertFile, c.KeyFile) // "example-cert.pem" "example-key.pem if err != nil...
-
March 29, 2022
Linux的lo网络设备loopback
dev.c 文件里面net_dev_init 函数会为每个net创建和初始化loopback_dev,在路由模块等地方会引用到这个loopback设备。 典型的比如local output的流量在 ip rule里面对应的iif就是 lo(loop back)设备。struct net { struct net_device *loopback_dev; /* The loopback */}/* Setup and register the loop...
-
March 24, 2022
Jsoniter里面解码某个json节点为特定struct
package mainimport ( jsoniter "github.com/json-iterator/go")type Info map[string]stringfunc main() { input := []byte(`{"type":"test","desc":"test","info":[{"a": "dd", "b":"ddd"}]}`) m := map[string]interface{}{} var info []GuestInfo var json = jso...
-
February 09, 2022
Netfilter自定义target和iptables的支持 以nflog为例
http://git.netfilter.org/iptables/tree/extensions/libipt_ULOG.chttps://elixir.bootlin.com/linux/latest/source/net/netfilter/nfnetlink_log.c https://elixir.bootlin.com/linux/latest/source/net/netfilter/nf_log_syslog.c https://elixir.bootlin.com/l...
-
January 08, 2022
Bpf和xdp代码的编译和加载和redhat的xdp Filter防火墙过滤
需要用clang把c语言写的代码编译成ebpf的object文件,然后用工具把object文件加载到内核。不过也有纯golang的库用于编译和调试ebpf的 https://github.com/cilium/ebpf也有很多辅助工具用于加载bpf代码,比如https://github.com/iovisor/bcc 用于调试分析系统,已经集成了很多脚本了吧,好像可以取代systemtap.BPF and XDP Reference Guide https://docs.cilium.i...
-
January 07, 2022
基于bpf技术的文件和进程安全监控项目falco
https://github.com/falcosecurity/falcohttps://falco.org/docs/可以根据配置的规则把文件变化、进程和socket事件通过grpc发送告警。What does Falco do?Falco uses system calls to secure and monitor a system, by:Parsing the Linux system calls from the kernel at runtimeAsserting the ...