diff --git a/docker/run/DockerfileKali b/docker/run/DockerfileKali new file mode 100644 index 000000000..f5808cdce --- /dev/null +++ b/docker/run/DockerfileKali @@ -0,0 +1,33 @@ +# Use the latest slim version of Kali Linux +FROM kalilinux/kali-rolling + +# Check if the argument is provided, else throw an error +ARG BRANCH +RUN if [ -z "$BRANCH" ]; then echo "ERROR: BRANCH is not set!" >&2; exit 1; fi +ENV BRANCH=$BRANCH + +# Copy contents of the project to /a0 +COPY ./fs/ / + +# pre installation steps +RUN bash /ins/pre_install.sh $BRANCH +RUN bash /ins/pre_install_kali.sh $BRANCH + +# install additional software +RUN bash /ins/install_additional.sh $BRANCH + +# install A0 +RUN bash /ins/install_A0.sh $BRANCH + +# cleanup repo and install A0 without caching, this speeds up builds +ARG CACHE_DATE=none +RUN echo "cache buster $CACHE_DATE" && bash /ins/install_A02.sh $BRANCH + +# post installation steps +RUN bash /ins/post_install.sh $BRANCH + +# Expose ports +EXPOSE 22 80 + +# initialize runtime +CMD ["/bin/bash", "-c", "/bin/bash /exe/initialize.sh $BRANCH"] \ No newline at end of file diff --git a/docker/run/build.txt b/docker/run/build.txt index 5dfde71e7..94b6ed213 100644 --- a/docker/run/build.txt +++ b/docker/run/build.txt @@ -4,6 +4,9 @@ docker build -t agent-zero-run:local --build-arg BRANCH=development --build-arg # local image without cache docker build -t agent-zero-run:local --build-arg BRANCH=development --no-cache . +# local image from Kali +docker build -f ./DockerfileKali -t agent-zero-run:hacking --build-arg BRANCH=main --build-arg CACHE_DATE=$(date +%Y-%m-%d:%H:%M:%S) . + # dockerhub push: docker login diff --git a/docker/run/fs/ins/install_additional.sh b/docker/run/fs/ins/install_additional.sh index e857ef471..477ef6e85 100644 --- a/docker/run/fs/ins/install_additional.sh +++ b/docker/run/fs/ins/install_additional.sh @@ -1,4 +1,7 @@ #!/bin/bash +# install playwright +bash /ins/install_playwright.sh "$@" + # searxng bash /ins/install_searxng.sh "$@" \ No newline at end of file diff --git a/docker/run/fs/ins/install_playwright.sh b/docker/run/fs/ins/install_playwright.sh index cd5755424..eca6ab98a 100644 --- a/docker/run/fs/ins/install_playwright.sh +++ b/docker/run/fs/ins/install_playwright.sh @@ -7,4 +7,12 @@ pip install playwright # install chromium with dependencies -playwright install --with-deps chromium-headless-shell +# for kali-based +if [ "$@" = "hacking" ]; then + apt-get install -y fonts-unifont libnss3 libnspr4 + playwright install chromium-headless-shell +else + # for debian based + playwright install --with-deps chromium-headless-shell +fi + diff --git a/docker/run/fs/ins/install_searxng.sh b/docker/run/fs/ins/install_searxng.sh index fdc7775ad..ee9ad3d1c 100644 --- a/docker/run/fs/ins/install_searxng.sh +++ b/docker/run/fs/ins/install_searxng.sh @@ -2,7 +2,7 @@ # Install necessary packages apt-get install -y \ - python3-dev python3-babel python3-venv \ + python3.12-dev python3-babel python3.12-venv \ uwsgi uwsgi-plugin-python3 \ git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev diff --git a/docker/run/fs/ins/post_install.sh b/docker/run/fs/ins/post_install.sh index c1a7e1d18..410ff19a7 100644 --- a/docker/run/fs/ins/post_install.sh +++ b/docker/run/fs/ins/post_install.sh @@ -1,8 +1,5 @@ #!/bin/bash -# install playwright -bash /ins/install_playwright.sh "$@" - # Cleanup package list rm -rf /var/lib/apt/lists/* apt-get clean \ No newline at end of file diff --git a/docker/run/fs/ins/pre_install.sh b/docker/run/fs/ins/pre_install.sh index 74a78844f..48d6ed5ae 100644 --- a/docker/run/fs/ins/pre_install.sh +++ b/docker/run/fs/ins/pre_install.sh @@ -2,9 +2,8 @@ # Update and install necessary packages apt-get update && apt-get install -y \ - python3 \ - python3-pip \ - python3-venv \ + python3.12 \ + python3.12-venv \ nodejs \ npm \ openssh-server \ @@ -14,5 +13,18 @@ apt-get update && apt-get install -y \ git \ ffmpeg -# prepare SSH daemon -bash /ins/setup_ssh.sh "$@" \ No newline at end of file +# Configure system alternatives so that /usr/bin/python3 points to Python 3.12 +sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 +sudo update-alternatives --set python3 /usr/bin/python3.12 + +# Update pip3 symlink: if pip3.12 exists, point pip3 to it; +# otherwise, install pip using Python 3.12's ensurepip. +if [ -f /usr/bin/pip3.12 ]; then + sudo ln -sf /usr/bin/pip3.12 /usr/bin/pip3 +else + python3 -m ensurepip --upgrade + python3 -m pip install --upgrade pip +fi + +# Prepare SSH daemon +bash /ins/setup_ssh.sh "$@" diff --git a/docker/run/fs/ins/pre_install_kali.sh b/docker/run/fs/ins/pre_install_kali.sh new file mode 100644 index 000000000..dffcbdff3 --- /dev/null +++ b/docker/run/fs/ins/pre_install_kali.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# ubuntu based dependencies for playwright +# moved to install_playwright.sh +# apt-get update && apt-get install -y fonts-unifont fonts-ubuntu + diff --git a/docker/run/fs/ins/setup_ssh.sh b/docker/run/fs/ins/setup_ssh.sh index 958323623..331e905fc 100644 --- a/docker/run/fs/ins/setup_ssh.sh +++ b/docker/run/fs/ins/setup_ssh.sh @@ -1,6 +1,6 @@ #!/bin/bash # Set up SSH -mkdir /var/run/sshd && \ +mkdir -p /var/run/sshd && \ # echo 'root:toor' | chpasswd && \ sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \ No newline at end of file diff --git a/python/helpers/dirty_json.py b/python/helpers/dirty_json.py index 28054ff10..b65c120db 100644 --- a/python/helpers/dirty_json.py +++ b/python/helpers/dirty_json.py @@ -103,9 +103,14 @@ class DirtyJson: return None def _match(self, text: str) -> bool: - cnt = len(text) - if self._peek(cnt).lower() == text.lower(): - self._advance(cnt) + # first char should match current char + if not self.current_char or self.current_char.lower() != text[0].lower(): + return False + + # peek remaining chars + remaining = len(text) - 1 + if self._peek(remaining).lower() == text[1:].lower(): + self._advance(len(text)) return True return False @@ -187,6 +192,13 @@ class DirtyJson: self._skip_whitespace() if self.current_char == ',': self._advance() + # handle trailing commas, end of array + self._skip_whitespace() + if self.current_char is None or self.current_char == ']': + if self.current_char == ']': + self._advance() + self.stack.pop() + return elif self.current_char != ']': self.stack.pop() return @@ -245,30 +257,6 @@ class DirtyJson: except ValueError: return float(number_str) - def _parse_true(self): - self._advance() - for char in 'rue': - if self.current_char != char: - return None - self._advance() - return True - - def _parse_false(self): - self._advance() - for char in 'alse': - if self.current_char != char: - return None - self._advance() - return False - - def _parse_null(self): - self._advance() - for char in 'ull': - if self.current_char != char: - return None - self._advance() - return None - def _parse_unquoted_string(self): result = "" while self.current_char is not None and self.current_char not in [':', ',', '}', ']']: diff --git a/python/helpers/history.py b/python/helpers/history.py index 766e01849..3f9e7c506 100644 --- a/python/helpers/history.py +++ b/python/helpers/history.py @@ -126,7 +126,7 @@ class Topic(Record): msg_max_size = ( set["chat_model_ctx_length"] * set["chat_model_ctx_history"] - * HISTORY_TOPIC_RATIO + * CURRENT_TOPIC_RATIO * LARGE_MESSAGE_TO_TOPIC_RATIO ) large_msgs = []