Package: kb-manager
kb. A minimalist knowledge base managerAuthor: gncnebbionegiuseppe@gmail.comCopyright: © 2020, gncDate: 2022-09-21Version: 0.1.7Purposekb is a text-oriented minimalist command line knowledge base manager. kb
can be considered a quick note collection and access tool oriented toward
software developers, penetration testers, hackers, students or whoever
has to collect and organize notes in a clean way.  Although kb is mainly
targeted on text-based note collection, it supports non-text files as well
(e.g., images, pdf, videos and others).The project was born from the frustration of trying to find a good way
to quickly access my notes, procedures, cheatsheets and lists (e.g.,
payloads) but at the same time, keeping them organized.  This is
particularly useful for any kind of student. I use it in the context
of penetration testing to organize pentesting procedures, cheatsheets,
payloads, guides and notes.I found myself too frequently spending time trying to search for that
particular payload list quickly, or spending too much time trying to find
a specific guide/cheatsheet for a needed tool. kb tries to solve this
problem by providing you a quick and intuitive way to access knowledge.In few words kb allows a user to quickly and efficiently:collect items containing notes,guides,procedures,cheatsheets into
an organized knowledge base;filter the knowledge base on different metadata: title, category,
tags and others;visualize items within the knowledge base with (or without) syntax
highlighting;grep through the knowledge base using regexes;import/export an entire knowledge base;Basically, kb provides a clean text-based way to organize your knowledge.InstallationYou should have Python 3.6 or above installed.To install the most recent stable version of kb just type:pipinstall-Ukb-managerIf you want to install the bleeding-edge version of kb (that may have
some bugs) you should do:gitclonehttps://github.com/gnebbia/kbcdkb
pipinstall-rrequirements.txt
pythonsetup.pyinstall# or with pippipinstall-Ugit+https://github.com/gnebbia/kbTipfor GNU/Linux and MacOS users: For a better user experience,
also set the following kb bash aliases:cat<<EOF > ~/.kb_aliasalias kbl="kb list"alias kbe="kb edit"alias kba="kb add"alias kbv="kb view"alias kbd="kb delete --id"alias kbg="kb grep"alias kbt="kb list --tags"EOFecho"source ~/.kb_alias">>~/.bashrcsource~/.kb_aliasPlease remember to upgrade kb frequently by doing:pipinstall-Ukb-managerInstallation with homebrewTo install using homebrew, use:brewtapgnebbia/kbhttps://github.com/gnebbia/kb.git
brewinstallgnebbia/kb/kbTo upgrade with homebrew:brewupdate
brewupgradegnebbia/kb/kbInstallation from AURArch Linux users can installkborkb-gitwith their favoriteAUR Helper.Stable:yay-SkbDev:yay-Skb-gitNotes for Windows usersWindows users should keep in mind these things:DO NOT USE notepad as %EDITOR%, kb is not compatible with notepad,
a reasonable alternative is notepad++;%EDITOR% variable should ALWAYS be enclosed within double quotes;EDITOR=C:\ProgramFiles\Editor\mycooleditor.exe->WRONG!EDITOR="C:\Program Files\Editor\my cool editor.exe"->OK!To set the "EDITOR" Environment variable by using cmd.exe, just issue
the following commands, after having inserted the path to your desired
text editor:setEDITOR="C:\path\to\editor\here.exe"setxEDITOR"\"C:\path\to\editor\here.exe\""To set the "EDITOR" Environment variable by using Powershell, just issue
the following commands, after having inserted the path to your desired
text editor:$env:EDITOR='"C:\path\to\editor\here.exe"'[System.Environment]::SetEnvironmentVariable('EDITOR','"C:\path\to\editor\here.exe"',[System.EnvironmentVariableTarget]::User)Setting Aliases for cmdOpen a cmd.exe terminal with administrative rights and paste
the following commands:regadd"HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor"/v"AutoRun"/tREG_EXPAND_SZ/d"%USERPROFILE%\autorun.cmd"(echo@echooffechodoskeykbl=kblist$*echodoskeykbe=kbedit$*echodoskeykba=kbadd$*echodoskeykbv=kbview$*echodoskeykbd=kbdelete--id$*echodoskeykbg=kbgrep$*echodoskeykbt=kblist--tags$*)>%USERPROFILE%\autorun.cmdSetting Aliases for PowershellOpen a Powershell terminal and paste the following commands:@'function kbl { kb list $args }function kbe { kb edit $args }function kba { kb add  $args }function kbv { kb view $args }function kbd { kb delete --id $args }function kbg { kb grep $args }function kbt { kb list --tags $args }'@>$env:USERPROFILE\Documents\WindowsPowerShell\profile.ps1DockerA docker setup has been included to help with development.To install and start the project with docker:docker-composeup-d
docker-composeexeckbbashThe container has the aliases included in its.bashrcso you can use
kb in the running container as you would if you installed it on the
host directly.  The./docker/datadirectory on the host is bound to/datain the container, which is the image's working directly also.
To interact with the container, place (or symlink) the files on your host
into the./docker/datadirectory, which can then be seen and used in
the/datadirectory in the container.UsageList artifactsList all artifacts contained in the kb knowledge basekblist# or if aliases are used:kblList all artifacts containing the string "zip"kblistzip# or if aliases are used:kblzipList all artifacts belonging to the category "cheatsheet"kblist--categorycheatsheet# orkblist-ccheatsheet# or if aliases are used:kbl-ccheatsheetList all the artifacts having the tags "web" or "pentest"kblist--tags"web;pentest"# or if aliases are used:kbl--tags"web;pentest"List using "verbose mode"kblist-v# or if aliases are used:kbl-vAdd artifactsAdd a file to the collection of artifactskbadd~/Notes/cheatsheets/pytest# or if aliases are used:kba~/Notes/cheatsheets/pytestAdd a file to the artifactskbadd~/ssh_tunnels--titlepentest_ssh--category"procedure"\--tags"pentest;network"--author"gnc"--status"draft"Add all files contained in a directory to kbkbadd~/Notes/cheatsheets/general/*--category"cheatsheet"Create a new artifact from scratchkbadd--title"ftp"--category"notes"--tags"protocol;network"# a text editor ($EDITOR) will be launched for editingCreate a new artifact from the output of another programkbadd--title"my_network_scan"--category"scans"--body"$(nmap-T5-p80192.168.1.0/24)"Delete artifactsDelete an artifact by IDkbdelete--id2# or if aliases are used:kbd2Delete multiple artifacts by IDkbdelete--id234# or if aliases are used:kbd234Delete an artifact by namekbdelete--titlezap--categorycheatsheetView artifactsView an artifact by idkbview--id3# orkbview-i3# orkbview3# or if aliases are used:kbv3View an artifact by namekbview--title"gobuster"# orkbview-t"gobuster"# orkbviewgobusterView an artifact without colorskbview-tdirb-nView an artifact within a text-editorkbview-i2-e# or if aliases are used:kbv2-eEdit artifactsEditing artifacts involves opening a text editor.
Hence, binary files cannot be edited by kb.The editor can be set by the "EDITOR" environment
variable.Edit an artifact by idkbedit--id13# orkbe13# or if aliases are used:kbe13Edit an artifact by namekbedit--title"git"--category"cheatsheet"# orkbedit-t"git"-c"cheatsheet"# or if git is unique as artifactkbeditgitGrep through artifactsGrep through the knowledge basekbgrep"[bg]zip"# or if aliases are used:kbg"[bg]zip"Grep (case-insensitive) through the knowledge basekbgrep-i"[BG]ZIP"Grep in "verbose mode" through the knowledge basekbgrep-v"[bg]zip"Grep through the knowledge base and show matching lineskbgrep-m"[bg]zip"Import/Export/Erase a knowledge baseExport the current knowledge baseTo export the entire knowledge base, do:kbexportThis will generate a .kb.tar.gz archive that can
be later be imported by kb.If you want to export only data (so that it can be used in other software):kbexport--only-dataThis will export a directory containing a subdirectory for each category
and within these subdirectories we will have all the artifacts belonging
to that specific category.Import a knowledge basekbimportarchive.kb.tar.gzNOTE: Importing a knowledge base erases all the previous
data. Basically it erases everything and imports the new knowledge base.Erase the entire knowledge basekberaseManage Templateskb supports custom templates for the artifacts.
A template is basically a file using the "toml" format,
structured in this way:TITLES=["^#.*","blue",]WARNINGS=["!.*","yellow",]COMMENTS=[";;.*","green",]Where the first element of each list is a regex and the second element
is a color.Note that by default an artifact is assigned with the 'default'
template, and this template can be changed too (look at "Edit a template"
subsection).List available templatesTo list all available templates:kbtemplatelistTo list all the templates containing the string "theory":kbtemplatelist"theory"Create a new templateCreate a new template called "lisp-cheatsheets", note that
an example template will be put as example in the editor.kbtemplatenewlisp-cheatsheetsDelete a templateTo delete the template called "lisp-cheatsheets" just do:kbtemplatedeletelisp-cheatsheetsEdit a templateTo edit the template called "listp-cheatsheets" just do:kbtemplateeditlisp-cheatsheetsAdd a templateWe can also add a template from an already existing toml configuration file
by just doing:kbtemplateadd~/path/to/myconfig.toml--titlemyconfigChange template for an artifactWe can change the template for an existing artifact by ID by using the
update command:kbupdate--id2--template"lisp-cheatsheets"Apply a template to all artifacts of a categoryWe can apply the template "lisp-cheatsheets" to all artifacts
belonging to the category "lispcode" by doing:kbtemplateapply"lisp-cheatsheets"--category"lispcode"Apply a template to all artifacts having zip in their titleWe can apply the template "dark" to all artifacts having in their title
the string "zip" (e.g., bzip, 7zip, zipper) by doing:kbtemplateapply"dark"--title"zip"--extended-match# orkbtemplateapply"dark"--title"zip"-mWe can always have our queries to "contain" the string by using
the--extended-matchoption when usingkb template apply.Apply a template to all artifacts having specific propertiesWe can apply the template "light" to all artifacts of the category
"cheatsheet" who have as author "gnc" and as status "OK" by doing:kbtemplateapply"light"--category"cheatsheet"--author"gnc"--status"OK"Integrating kb with other toolskb can be integrated with other tools.kb and rofiWe can integrate kb with rofi, a custom mode has been developed
accessible in the "misc" directory within this repository.We can launch rofi with this mode by doing:rofi-showkb-modikb:/path/to/rofi-kb-mode.shExperimentalSynchronize kb with a remote git repositorySynchronization with a remote git repository is experimental at the moment.
Anyway we can initialize our knowledge base to a created empty
github/gitlab (other git service) repository by doing:kbsyncinitWe can then push our knowledge base to the remote git repository with:kbsyncpushWe can pull (e.g., from another machine) our knowledge base from the
remote git repository with:kbsyncpullWe can at any time view to what remote endpoint our knowledge is synchronizing
to with:kbsyncinfoUPGRADEIf you want to upgrade kb to the most recent stable release do:pipinstall-Ukb-managerIf instead you want to update kb to the most recent release
(that may be bugged), do:gitclonehttps://github.com/gnebbia/kbcdkb
pipinstall--upgrade.DONATIONSI am an independent developer working on kb in my free time,
if you like kb and would like to say thank you, buy me a beer!COPYRIGHTCopyright 2020 Giuseppe Nebbione.This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program.  If not, seehttp://www.gnu.org/licenses/.