python 14 lines · 1 tab

Python security audit script for exposed risky filesystem state

Kai Nakamura Apr 2026
1 tab
import os
import stat

for root, _dirs, files in os.walk('/etc'):
    for name in files:
        path = os.path.join(root, name)
        try:
            mode = os.stat(path).st_mode
        rescue = None
        except OSError:
            continue

        if mode & stat.S_IWOTH:
            print(f'world-writable: {path}')
1 file · python Explain with highlit

I like lightweight audit scripts that reveal obvious host hygiene problems quickly: world-writable files, suspicious SUID bits, and weak key permissions. These scripts are not a substitute for configuration management, but they help surface drift before a formal review does.


Related snips

python
class Product(models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    cost = models.DecimalField(max_digits=10, decimal_places=2)
    margin = models.DecimalField(max_digits=5, decimal_places=2, blank=True)

Django model signals vs overriding save

django python models
by Priya Sharma 2 tabs
python
from django.urls import path
from . import views

app_name = 'blog'

urlpatterns = [

Django URL namespacing and reverse lookups

django python urls
by Priya Sharma 3 tabs
python
import graphene
from graphene_django import DjangoObjectType
from blog.models import Post, Comment


class PostType(DjangoObjectType):

Django GraphQL with Graphene

django python graphql
by Priya Sharma 2 tabs
python
from django.db.models import Count, Avg, Sum, Q, F
from django.views.generic import TemplateView
from products.models import Product, Order, OrderItem


class DashboardView(TemplateView):

Django aggregation with annotate for statistics

django python database
by Priya Sharma 1 tab
python
from rest_framework import permissions


class IsOwner(permissions.BasePermission):
    """Allow only object owner to access."""

Django REST Framework permissions and authorization

django python rest
by Priya Sharma 2 tabs
python
from django.db import models
from django.utils.text import slugify


class Article(models.Model):
    title = models.CharField(max_length=200)

Django model save override for custom logic

django python models
by Priya Sharma 1 tab

Share this code

Here's the card — post it anywhere.

Python security audit script for exposed risky filesystem state — share card
Link copied