GithubHelp home page GithubHelp logo

strang1ato / nhi Goto Github PK

View Code? Open in Web Editor NEW
290.0 5.0 11.0 4.02 MB

:tv: Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

License: GNU General Public License v3.0

Makefile 2.42% Go 47.24% C 43.63% Shell 6.72%
ebpf bpf linux kernel shell bash zsh c go golang

nhi's Introduction

On hiatus until the end of May.

nhi's People

Contributors

strang1ato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nhi's Issues

Output of commands not saved when vim is ran

Hello,

Thank you, this project is really cool!

However, my commands are not logged after running commands such as vim:

vagrant@bullseye:~$ nhi fetch {-1}
vagrant@bullseye:~$ echo test
test
vagrant@bullseye:~$ vim
vagrant@bullseye:~$ echo test
(nothing here)

This issue seems to come from here:

nhi/daemon/src/nhi.bpf.c

Lines 393 to 404 in a3c65cc

} else if (write_event->output[i+7] == 'l') {
helper->omit_write = 0;
bpf_map_update_elem(&shells, &shell_index, helper, BPF_ANY);
write_event->output[i] = 0;
write_event->output[i+1] = 0;
write_event->output[i+2] = 0;
write_event->output[i+3] = 0;
write_event->output[i+4] = 0;
write_event->output[i+5] = 0;
write_event->output[i+6] = 0;
write_event->output[i+7] = 0;
}

Looking in the database (at /var/nhi/db), I can see:

echo test
b'\xfftest\n'
vim
b'\xff\x1b[?1000h\xff\x1b[34h\x1b[?25h\x00\x00\x00\x00\x00\x00\x00\x00'
echo test
b''

The last 8 bytes are set to \x00 which should mean that omit_write is set to zero, but I do not understand why it still refuses to log the next commands.

On another note, it would be nice to remove the null bytes and the rest of what was logged (\x1b[?1000h\xff\x1b[34h\x1b[?25h), it messes up my terminal after executing nhi fetch (which makes me have to execute reset to clean my terminal).

Move to BPF magic

I am starting to moving from ptrace to BPF

BPF will take over nhi

`nhi` doesn't record commands

Installed from release 0.2.1, nhi fetch shows only the creation of sessions, no commands have been logged, nor the finish of sessions. Same result from within and without tmux

$ uname -a
Linux Aostro-5468 5.14.16-arch1-1 #1 SMP PREEMPT Tue, 02 Nov 2021 22:22:59 +0000 x86_64 GNU/Linux

$ zsh --version
zsh 5.8 (x86_64-pc-linux-gnu)

Update bash package in default-bash-and-zsh ppa with /etc/bash.bashrc support

On Ubuntu, while using nhi after following the install procedures outlined in the README.md, I noticed that my system-wide /etc/bash.bashrc was not getting sourced into my interactive shells (it still worked with login shells as /etc/profile loads the /etc/bash.bashrc). After digging into the issue, it seems like the issue starts after reinstalling the bash package from ppa:strang1ato/default-bash-and-zsh. After some Googling it looks like the issue might be due to a missing option (-DSYS_BASHRC) when bash is being compiled.

Simplified steps to reproduce on a clean Ubuntu 22.04 instance...

# ssh to the instance

sudo apt update
sudo apt upgrade
sudo bash -c 'echo "echo \"Hit: /etc/bash.bashrc\"" >> /etc/bash.bashrc'
echo "echo \"Hit: ~/.bashrc\"" >> ~/.bashrc

# exit and ssh back in to the instance, note you get two echos

bash

# note you get two echos

# next we will exit the interactive shell and go back to the login shell from ssh
exit

sudo apt remove zsh-common
sudo add-apt-repository ppa:strang1ato/default-bash-and-zsh
sudo apt update
sudo apt install --reinstall bash

# exit and ssh back in to the instance, note you get two echos

bash

# note you only get one echo

Thank you for this project and work!

Debian 11 problem

when i run
nhi fetch {-1}
i get
no such shell session: 0
source /etc/nhi/nhi.bash exists in ~/.bashrc , i am running everything as root
what could be wrong? Also where is the history of commands stored?
no log file in /tmp

no such shell session: 0

After following the install steps for other distributions I did run the tests commands to know if everything was good and got the following message after running nhi fetch;

$ nhi fetch {-1}
no such shell session: 0

Im using Debian bullseye and bash

`nhid` segfaults on 0.2.2 while using tmux

Not really an issue (probably because I haven't used nhi that much), but I saw this in the kernel messages:

[  +0.000004] nhid[3381461]: segfault at 0 ip 00007fed21d1f515 sp 00007ffd5ca83e38 error 4 in libc-2.33.so[7fed21be5000+14b000]
[  +0.000010] Code: 00 00 0f 1f 00 31 c0 c5 f8 77 c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 89 f9 48 89 fa c5 f9 ef c0 83 e1 3f 83 f9 20 77 2b <c5> fd 74 0f c5 fd d7 c1 85 c0 0f 85 eb 00 00 00 48 83 c7 20 83 e1

I don't know why there isn't a coredump generated, but it happens inside tmux and with my .zshrc (haven't tested other conditions yet). Again, not a urgent problem for me, just something for you to look into

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.