Yes - all Moodle code is GPL, so you can take it and modify it as much as you like, as long as you remember that everyone who gets a copy of your plugin can do the same.
I'm not sure what you mean by 'publish' - jf you mean to just stick it on github (or similar), then go for it. If you mean to add it to the Moodle plugins directory (on this site), then you may well find that it gets rejected if it is only a very subtle variation on the original 'folder' plugin (as it's not in anyone's interest for the Plugins directory to be full of lots of minor variations on core plugins). If, however, you're wanting to use it as a basis for creating something new and interesting, then it's much more likely to be accepted.
I'm not sure what you mean by 'publish' - jf you mean to just stick it on github (or similar), then go for it. If you mean to add it to the Moodle plugins directory (on this site), then you may well find that it gets rejected if it is only a very subtle variation on the original 'folder' plugin (as it's not in anyone's interest for the Plugins directory to be full of lots of minor variations on core plugins). If, however, you're wanting to use it as a basis for creating something new and interesting, then it's much more likely to be accepted.